diff --git a/external/dtEntity/include/dtEntity/FastDelegate.h b/external/dtEntity/include/dtEntity/FastDelegate.h new file mode 100644 index 000000000..48d90e269 --- /dev/null +++ b/external/dtEntity/include/dtEntity/FastDelegate.h @@ -0,0 +1,2111 @@ +#pragma once + +#ifndef FASTDELEGATE_H +#define FASTDELEGATE_H + +// FastDelegate.h +// Efficient delegates in C++ that generate only two lines of asm code! +// Documentation is found at http://www.codeproject.com/cpp/FastDelegate.asp +// +// - Don Clugston, Mar 2004. +// Major contributions were made by Jody Hagins. +// History: +// 24-Apr-04 1.0 * Submitted to CodeProject. +// 28-Apr-04 1.1 * Prevent most unsafe uses of evil static function hack. +// * Improved syntax for horrible_cast (thanks Paul Bludov). +// * Tested on Metrowerks MWCC and Intel ICL (IA32) +// * Compiled, but not run, on Comeau C++ and Intel Itanium ICL. +// 27-Jun-04 1.2 * Now works on Borland C++ Builder 5.5 +// * Now works on /clr "managed C++" code on VC7, VC7.1 +// * Comeau C++ now compiles without warnings. +// * Prevent the virtual inheritance case from being used on +// VC6 and earlier, which generate incorrect code. +// * Improved warning and error messages. Non-standard hacks +// now have compile-time checks to make them safer. +// * implicit_cast used instead of static_cast in many cases. +// * If calling a const member function, a const class pointer can be used. +// * MakeDelegate() global helper function added to simplify pass-by-value. +// * Added fastdelegate.clear() +// 16-Jul-04 1.2.1* Workaround for gcc bug (const member function pointers in templates) +// 30-Oct-04 1.3 * Support for (non-void) return values. +// * No more workarounds in client code! +// MSVC and Intel now use a clever hack invented by John Dlugosz: +// - The FASTDELEGATEDECLARE workaround is no longer necessary. +// - No more warning messages for VC6 +// * Less use of macros. Error messages should be more comprehensible. +// * Added include guards +// * Added FastDelegate::empty() to test if invocation is safe (Thanks Neville Franks). +// * Now tested on VS 2005 Express Beta, PGI C++ +// 24-Dec-04 1.4 * Added DelegateMemento, to allow collections of disparate delegates. +// * <,>,<=,>= comparison operators to allow storage in ordered containers. +// * Substantial reduction of code size, especially the 'Closure' class. +// * Standardised all the compiler-specific workarounds. +// * MFP conversion now works for CodePlay (but not yet supported in the full code). +// * Now compiles without warnings on _any_ supported compiler, including BCC 5.5.1 +// * New syntax: FastDelegate< int (char *, double) >. +// 14-Feb-05 1.4.1* Now treats =0 as equivalent to .clear(), ==0 as equivalent to .empty(). (Thanks elfric). +// * Now tested on Intel ICL for AMD64, VS2005 Beta for AMD64 and Itanium. +// 30-Mar-05 1.5 * Safebool idiom: "if (dg)" is now equivalent to "if (!dg.empty())" +// * Fully supported by CodePlay VectorC +// * Bugfix for Metrowerks: empty() was buggy because a valid MFP can be 0 on MWCC! +// * More optimal assignment,== and != operators for static function pointers. + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#include // to allow <,> comparisons + +//////////////////////////////////////////////////////////////////////////////// +// Configuration options +// +//////////////////////////////////////////////////////////////////////////////// + +// Uncomment the following #define for optimally-sized delegates. +// In this case, the generated asm code is almost identical to the code you'd get +// if the compiler had native support for delegates. +// It will not work on systems where sizeof(dataptr) < sizeof(codeptr). +// Thus, it will not work for DOS compilers using the medium model. +// It will also probably fail on some DSP systems. +#define FASTDELEGATE_USESTATICFUNCTIONHACK + +// Uncomment the next line to allow function declarator syntax. +// It is automatically enabled for those compilers where it is known to work. +//#define FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX + +//////////////////////////////////////////////////////////////////////////////// +// Compiler identification for workarounds +// +//////////////////////////////////////////////////////////////////////////////// + +// Compiler identification. It's not easy to identify Visual C++ because +// many vendors fraudulently define Microsoft's identifiers. +#if defined(_MSC_VER) && !defined(__MWERKS__) && !defined(__VECTOR_C) && !defined(__ICL) && !defined(__BORLANDC__) +#define FASTDLGT_ISMSVC + +#if (_MSC_VER <1300) // Many workarounds are required for VC6. +#define FASTDLGT_VC6 +#pragma warning(disable:4786) // disable this ridiculous warning +#endif + +#endif + +// Does the compiler uses Microsoft's member function pointer structure? +// If so, it needs special treatment. +// Metrowerks CodeWarrior, Intel, and CodePlay fraudulently define Microsoft's +// identifier, _MSC_VER. We need to filter Metrowerks out. +#if defined(_MSC_VER) && !defined(__MWERKS__) +#define FASTDLGT_MICROSOFT_MFP + +#if !defined(__VECTOR_C) +// CodePlay doesn't have the __single/multi/virtual_inheritance keywords +#define FASTDLGT_HASINHERITANCE_KEYWORDS +#endif +#endif + +// Does it allow function declarator syntax? The following compilers are known to work: +#if defined(FASTDLGT_ISMSVC) && (_MSC_VER >=1310) // VC 7.1 +#define FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX +#endif + +// Gcc(2.95+), and versions of Digital Mars, Intel and Comeau in common use. +#if defined (__DMC__) || defined(__GNUC__) || defined(__ICL) || defined(__COMO__) +#define FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX +#endif + +// It works on Metrowerks MWCC 3.2.2. From boost.Config it should work on earlier ones too. +#if defined (__MWERKS__) +#define FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX +#endif + +#ifdef __GNUC__ // Workaround GCC bug #8271 + // At present, GCC doesn't recognize constness of MFPs in templates +#define FASTDELEGATE_GCC_BUG_8271 +#endif + + + +//////////////////////////////////////////////////////////////////////////////// +// General tricks used in this code +// +// (a) Error messages are generated by typdefing an array of negative size to +// generate compile-time errors. +// (b) Warning messages on MSVC are generated by declaring unused variables, and +// enabling the "variable XXX is never used" warning. +// (c) Unions are used in a few compiler-specific cases to perform illegal casts. +// (d) For Microsoft and Intel, when adjusting the 'this' pointer, it's cast to +// (char *) first to ensure that the correct number of *bytes* are added. +// +//////////////////////////////////////////////////////////////////////////////// +// Helper templates +// +//////////////////////////////////////////////////////////////////////////////// + + +namespace fastdelegate { +namespace detail { // we'll hide the implementation details in a nested namespace. + +// implicit_cast< > +// I believe this was originally going to be in the C++ standard but +// was left out by accident. It's even milder than static_cast. +// I use it instead of static_cast<> to emphasize that I'm not doing +// anything nasty. +// Usage is identical to static_cast<> +template +inline OutputClass implicit_cast(InputClass input){ + return input; +} + +// horrible_cast< > +// This is truly evil. It completely subverts C++'s type system, allowing you +// to cast from any class to any other class. Technically, using a union +// to perform the cast is undefined behaviour (even in C). But we can see if +// it is OK by checking that the union is the same size as each of its members. +// horrible_cast<> should only be used for compiler-specific workarounds. +// Usage is identical to reinterpret_cast<>. + +// This union is declared outside the horrible_cast because BCC 5.5.1 +// can't inline a function with a nested class, and gives a warning. +template +union horrible_union{ + OutputClass out; + InputClass in; +}; + +template +inline OutputClass horrible_cast(const InputClass input){ + horrible_union u; + // Cause a compile-time error if in, out and u are not the same size. + // If the compile fails here, it means the compiler has peculiar + // unions which would prevent the cast from working. + typedef int ERROR_CantUseHorrible_cast[sizeof(InputClass)==sizeof(u) + && sizeof(InputClass)==sizeof(OutputClass) ? 1 : -1]; + u.in = input; + return u.out; +} + +//////////////////////////////////////////////////////////////////////////////// +// Workarounds +// +//////////////////////////////////////////////////////////////////////////////// + +// Backwards compatibility: This macro used to be necessary in the virtual inheritance +// case for Intel and Microsoft. Now it just forward-declares the class. +#define FASTDELEGATEDECLARE(CLASSNAME) class CLASSNAME; + +// Prevent use of the static function hack with the DOS medium model. +#ifdef __MEDIUM__ +#undef FASTDELEGATE_USESTATICFUNCTIONHACK +#endif + +// DefaultVoid - a workaround for 'void' templates in VC6. +// +// (1) VC6 and earlier do not allow 'void' as a default template argument. +// (2) They also doesn't allow you to return 'void' from a function. +// +// Workaround for (1): Declare a dummy type 'DefaultVoid' which we use +// when we'd like to use 'void'. We convert it into 'void' and back +// using the templates DefaultVoidToVoid<> and VoidToDefaultVoid<>. +// Workaround for (2): On VC6, the code for calling a void function is +// identical to the code for calling a non-void function in which the +// return value is never used, provided the return value is returned +// in the EAX register, rather than on the stack. +// This is true for most fundamental types such as int, enum, void *. +// Const void * is the safest option since it doesn't participate +// in any automatic conversions. But on a 16-bit compiler it might +// cause extra code to be generated, so we disable it for all compilers +// except for VC6 (and VC5). +#ifdef FASTDLGT_VC6 +// VC6 workaround +typedef const void * DefaultVoid; +#else +// On any other compiler, just use a normal void. +typedef void DefaultVoid; +#endif + +// Translate from 'DefaultVoid' to 'void'. +// Everything else is unchanged +template +struct DefaultVoidToVoid { typedef T type; }; + +template <> +struct DefaultVoidToVoid { typedef void type; }; + +// Translate from 'void' into 'DefaultVoid' +// Everything else is unchanged +template +struct VoidToDefaultVoid { typedef T type; }; + +template <> +struct VoidToDefaultVoid { typedef DefaultVoid type; }; + + + +//////////////////////////////////////////////////////////////////////////////// +// Fast Delegates, part 1: +// +// Conversion of member function pointer to a standard form +// +//////////////////////////////////////////////////////////////////////////////// + +// GenericClass is a fake class, ONLY used to provide a type. +// It is vitally important that it is never defined, so that the compiler doesn't +// think it can optimize the invocation. For example, Borland generates simpler +// code if it knows the class only uses single inheritance. + +// Compilers using Microsoft's structure need to be treated as a special case. +#ifdef FASTDLGT_MICROSOFT_MFP + +#ifdef FASTDLGT_HASINHERITANCE_KEYWORDS + // For Microsoft and Intel, we want to ensure that it's the most efficient type of MFP + // (4 bytes), even when the /vmg option is used. Declaring an empty class + // would give 16 byte pointers in this case.... + class __single_inheritance GenericClass; +#endif + // ...but for Codeplay, an empty class *always* gives 4 byte pointers. + // If compiled with the /clr option ("managed C++"), the JIT compiler thinks + // it needs to load GenericClass before it can call any of its functions, + // (compiles OK but crashes at runtime!), so we need to declare an + // empty class to make it happy. + // Codeplay and VC4 can't cope with the unknown_inheritance case either. + class GenericClass {}; +#else + class GenericClass; +#endif + +// The size of a single inheritance member function pointer. +const int SINGLE_MEMFUNCPTR_SIZE = sizeof(void (GenericClass::*)()); + +// SimplifyMemFunc< >::Convert() +// +// A template function that converts an arbitrary member function pointer into the +// simplest possible form of member function pointer, using a supplied 'this' pointer. +// According to the standard, this can be done legally with reinterpret_cast<>. +// For (non-standard) compilers which use member function pointers which vary in size +// depending on the class, we need to use knowledge of the internal structure of a +// member function pointer, as used by the compiler. Template specialization is used +// to distinguish between the sizes. Because some compilers don't support partial +// template specialisation, I use full specialisation of a wrapper struct. + +// general case -- don't know how to convert it. Force a compile failure +template +struct SimplifyMemFunc { + template + inline static GenericClass *Convert(X *pthis, XFuncType function_to_bind, + GenericMemFuncType &bound_func) { + // Unsupported member function type -- force a compile failure. + // (it's illegal to have a array with negative size). + typedef char ERROR_Unsupported_member_function_pointer_on_this_compiler[N-100]; + return 0; + } +}; + +// For compilers where all member func ptrs are the same size, everything goes here. +// For non-standard compilers, only single_inheritance classes go here. +template <> +struct SimplifyMemFunc { + template + inline static GenericClass *Convert(X *pthis, XFuncType function_to_bind, + GenericMemFuncType &bound_func) { +#if defined __DMC__ + // Digital Mars doesn't allow you to cast between abitrary PMF's, + // even though the standard says you can. The 32-bit compiler lets you + // static_cast through an int, but the DOS compiler doesn't. + bound_func = horrible_cast(function_to_bind); +#else + bound_func = reinterpret_cast(function_to_bind); +#endif + return reinterpret_cast(pthis); + } +}; + +//////////////////////////////////////////////////////////////////////////////// +// Fast Delegates, part 1b: +// +// Workarounds for Microsoft and Intel +// +//////////////////////////////////////////////////////////////////////////////// + + +// Compilers with member function pointers which violate the standard (MSVC, Intel, Codeplay), +// need to be treated as a special case. +#ifdef FASTDLGT_MICROSOFT_MFP + +// We use unions to perform horrible_casts. I would like to use #pragma pack(push, 1) +// at the start of each function for extra safety, but VC6 seems to ICE +// intermittently if you do this inside a template. + +// __multiple_inheritance classes go here +// Nasty hack for Microsoft and Intel (IA32 and Itanium) +template<> +struct SimplifyMemFunc< SINGLE_MEMFUNCPTR_SIZE + sizeof(int) > { + template + inline static GenericClass *Convert(X *pthis, XFuncType function_to_bind, + GenericMemFuncType &bound_func) { + // We need to use a horrible_cast to do this conversion. + // In MSVC, a multiple inheritance member pointer is internally defined as: + union { + XFuncType func; + struct { + GenericMemFuncType funcaddress; // points to the actual member function + int delta; // #BYTES to be added to the 'this' pointer + }s; + } u; + // Check that the horrible_cast will work + typedef int ERROR_CantUsehorrible_cast[sizeof(function_to_bind)==sizeof(u.s)? 1 : -1]; + u.func = function_to_bind; + bound_func = u.s.funcaddress; + return reinterpret_cast(reinterpret_cast(pthis) + u.s.delta); + } +}; + +// virtual inheritance is a real nuisance. It's inefficient and complicated. +// On MSVC and Intel, there isn't enough information in the pointer itself to +// enable conversion to a closure pointer. Earlier versions of this code didn't +// work for all cases, and generated a compile-time error instead. +// But a very clever hack invented by John M. Dlugosz solves this problem. +// My code is somewhat different to his: I have no asm code, and I make no +// assumptions about the calling convention that is used. + +// In VC++ and ICL, a virtual_inheritance member pointer +// is internally defined as: +struct MicrosoftVirtualMFP { + void (GenericClass::*codeptr)(); // points to the actual member function + int delta; // #bytes to be added to the 'this' pointer + int vtable_index; // or 0 if no virtual inheritance +}; +// The CRUCIAL feature of Microsoft/Intel MFPs which we exploit is that the +// m_codeptr member is *always* called, regardless of the values of the other +// members. (This is *not* true for other compilers, eg GCC, which obtain the +// function address from the vtable if a virtual function is being called). +// Dlugosz's trick is to make the codeptr point to a probe function which +// returns the 'this' pointer that was used. + +// Define a generic class that uses virtual inheritance. +// It has a trival member function that returns the value of the 'this' pointer. +struct GenericVirtualClass : virtual public GenericClass +{ + typedef GenericVirtualClass * (GenericVirtualClass::*ProbePtrType)(); + GenericVirtualClass * GetThis() { return this; } +}; + +// __virtual_inheritance classes go here +template <> +struct SimplifyMemFunc +{ + + template + inline static GenericClass *Convert(X *pthis, XFuncType function_to_bind, + GenericMemFuncType &bound_func) { + union { + XFuncType func; + GenericClass* (X::*ProbeFunc)(); + MicrosoftVirtualMFP s; + } u; + u.func = function_to_bind; + bound_func = reinterpret_cast(u.s.codeptr); + union { + GenericVirtualClass::ProbePtrType virtfunc; + MicrosoftVirtualMFP s; + } u2; + // Check that the horrible_cast<>s will work + typedef int ERROR_CantUsehorrible_cast[sizeof(function_to_bind)==sizeof(u.s) + && sizeof(function_to_bind)==sizeof(u.ProbeFunc) + && sizeof(u2.virtfunc)==sizeof(u2.s) ? 1 : -1]; + // Unfortunately, taking the address of a MF prevents it from being inlined, so + // this next line can't be completely optimised away by the compiler. + u2.virtfunc = &GenericVirtualClass::GetThis; + u.s.codeptr = u2.s.codeptr; + return (pthis->*u.ProbeFunc)(); + } +}; + +#if (_MSC_VER <1300) + +// Nasty hack for Microsoft Visual C++ 6.0 +// unknown_inheritance classes go here +// There is a compiler bug in MSVC6 which generates incorrect code in this case!! +template <> +struct SimplifyMemFunc +{ + template + inline static GenericClass *Convert(X *pthis, XFuncType function_to_bind, + GenericMemFuncType &bound_func) { + // There is an apalling but obscure compiler bug in MSVC6 and earlier: + // vtable_index and 'vtordisp' are always set to 0 in the + // unknown_inheritance case! + // This means that an incorrect function could be called!!! + // Compiling with the /vmg option leads to potentially incorrect code. + // This is probably the reason that the IDE has a user interface for specifying + // the /vmg option, but it is disabled - you can only specify /vmg on + // the command line. In VC1.5 and earlier, the compiler would ICE if it ever + // encountered this situation. + // It is OK to use the /vmg option if /vmm or /vms is specified. + + // Fortunately, the wrong function is only called in very obscure cases. + // It only occurs when a derived class overrides a virtual function declared + // in a virtual base class, and the member function + // points to the *Derived* version of that function. The problem can be + // completely averted in 100% of cases by using the *Base class* for the + // member fpointer. Ie, if you use the base class as an interface, you'll + // stay out of trouble. + // Occasionally, you might want to point directly to a derived class function + // that isn't an override of a base class. In this case, both vtable_index + // and 'vtordisp' are zero, but a virtual_inheritance pointer will be generated. + // We can generate correct code in this case. To prevent an incorrect call from + // ever being made, on MSVC6 we generate a warning, and call a function to + // make the program crash instantly. + typedef char ERROR_VC6CompilerBug[-100]; + return 0; + } +}; + + +#else + +// Nasty hack for Microsoft and Intel (IA32 and Itanium) +// unknown_inheritance classes go here +// This is probably the ugliest bit of code I've ever written. Look at the casts! +// There is a compiler bug in MSVC6 which prevents it from using this code. +template <> +struct SimplifyMemFunc +{ + template + inline static GenericClass *Convert(X *pthis, XFuncType function_to_bind, + GenericMemFuncType &bound_func) { + // The member function pointer is 16 bytes long. We can't use a normal cast, but + // we can use a union to do the conversion. + union { + XFuncType func; + // In VC++ and ICL, an unknown_inheritance member pointer + // is internally defined as: + struct { + GenericMemFuncType m_funcaddress; // points to the actual member function + int delta; // #bytes to be added to the 'this' pointer + int vtordisp; // #bytes to add to 'this' to find the vtable + int vtable_index; // or 0 if no virtual inheritance + } s; + } u; + // Check that the horrible_cast will work + typedef int ERROR_CantUsehorrible_cast[sizeof(XFuncType)==sizeof(u.s)? 1 : -1]; + u.func = function_to_bind; + bound_func = u.s.funcaddress; + int virtual_delta = 0; + if (u.s.vtable_index) { // Virtual inheritance is used + // First, get to the vtable. + // It is 'vtordisp' bytes from the start of the class. + const int * vtable = *reinterpret_cast( + reinterpret_cast(pthis) + u.s.vtordisp ); + + // 'vtable_index' tells us where in the table we should be looking. + virtual_delta = u.s.vtordisp + *reinterpret_cast( + reinterpret_cast(vtable) + u.s.vtable_index); + } + // The int at 'virtual_delta' gives us the amount to add to 'this'. + // Finally we can add the three components together. Phew! + return reinterpret_cast( + reinterpret_cast(pthis) + u.s.delta + virtual_delta); + }; +}; +#endif // MSVC 7 and greater + +#endif // MS/Intel hacks + +} // namespace detail + +//////////////////////////////////////////////////////////////////////////////// +// Fast Delegates, part 2: +// +// Define the delegate storage, and cope with static functions +// +//////////////////////////////////////////////////////////////////////////////// + +// DelegateMemento -- an opaque structure which can hold an arbitary delegate. +// It knows nothing about the calling convention or number of arguments used by +// the function pointed to. +// It supplies comparison operators so that it can be stored in STL collections. +// It cannot be set to anything other than null, nor invoked directly: +// it must be converted to a specific delegate. + +// Implementation: +// There are two possible implementations: the Safe method and the Evil method. +// DelegateMemento - Safe version +// +// This implementation is standard-compliant, but a bit tricky. +// A static function pointer is stored inside the class. +// Here are the valid values: +// +-- Static pointer --+--pThis --+-- pMemFunc-+-- Meaning------+ +// | 0 | 0 | 0 | Empty | +// | !=0 |(dontcare)| Invoker | Static function| +// | 0 | !=0 | !=0* | Method call | +// +--------------------+----------+------------+----------------+ +// * For Metrowerks, this can be 0. (first virtual function in a +// single_inheritance class). +// When stored stored inside a specific delegate, the 'dontcare' entries are replaced +// with a reference to the delegate itself. This complicates the = and == operators +// for the delegate class. + +// DelegateMemento - Evil version +// +// For compilers where data pointers are at least as big as code pointers, it is +// possible to store the function pointer in the this pointer, using another +// horrible_cast. In this case the DelegateMemento implementation is simple: +// +--pThis --+-- pMemFunc-+-- Meaning---------------------+ +// | 0 | 0 | Empty | +// | !=0 | !=0* | Static function or method call| +// +----------+------------+-------------------------------+ +// * For Metrowerks, this can be 0. (first virtual function in a +// single_inheritance class). +// Note that the Sun C++ and MSVC documentation explicitly state that they +// support static_cast between void * and function pointers. + +class DelegateMemento { +protected: + // the data is protected, not private, because many + // compilers have problems with template friends. + typedef void (detail::GenericClass::*GenericMemFuncType)(); // arbitrary MFP. + detail::GenericClass *m_pthis; + GenericMemFuncType m_pFunction; + +#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + typedef void (*GenericFuncPtr)(); // arbitrary code pointer + GenericFuncPtr m_pStaticFunction; +#endif + +public: +#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + DelegateMemento() : m_pthis(0), m_pFunction(0), m_pStaticFunction(0) {}; + void clear() { + m_pthis=0; m_pFunction=0; m_pStaticFunction=0; + } +#else + DelegateMemento() : m_pthis(0), m_pFunction(0) {}; + void clear() { m_pthis=0; m_pFunction=0; } +#endif +public: +#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + inline bool IsEqual (const DelegateMemento &x) const{ + // We have to cope with the static function pointers as a special case + if (m_pFunction!=x.m_pFunction) return false; + // the static function ptrs must either both be equal, or both be 0. + if (m_pStaticFunction!=x.m_pStaticFunction) return false; + if (m_pStaticFunction!=0) return m_pthis==x.m_pthis; + else return true; + } +#else // Evil Method + inline bool IsEqual (const DelegateMemento &x) const{ + return m_pthis==x.m_pthis && m_pFunction==x.m_pFunction; + } +#endif + // Provide a strict weak ordering for DelegateMementos. + inline bool IsLess(const DelegateMemento &right) const { + // deal with static function pointers first +#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + if (m_pStaticFunction !=0 || right.m_pStaticFunction!=0) + return m_pStaticFunction < right.m_pStaticFunction; +#endif + if (m_pthis !=right.m_pthis) return m_pthis < right.m_pthis; + // There are no ordering operators for member function pointers, + // but we can fake one by comparing each byte. The resulting ordering is + // arbitrary (and compiler-dependent), but it permits storage in ordered STL containers. + return memcmp(&m_pFunction, &right.m_pFunction, sizeof(m_pFunction)) < 0; + + } + // BUGFIX (Mar 2005): + // We can't just compare m_pFunction because on Metrowerks, + // m_pFunction can be zero even if the delegate is not empty! + inline bool operator ! () const // Is it bound to anything? + { return m_pthis==0 && m_pFunction==0; } + inline bool empty() const // Is it bound to anything? + { return m_pthis==0 && m_pFunction==0; } +public: + DelegateMemento & operator = (const DelegateMemento &right) { + SetMementoFrom(right); + return *this; + } + inline bool operator <(const DelegateMemento &right) { + return IsLess(right); + } + inline bool operator >(const DelegateMemento &right) { + return right.IsLess(*this); + } + DelegateMemento (const DelegateMemento &right) : + m_pthis(right.m_pthis), m_pFunction(right.m_pFunction) +#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + , m_pStaticFunction (right.m_pStaticFunction) +#endif + {} +protected: + void SetMementoFrom(const DelegateMemento &right) { + m_pFunction = right.m_pFunction; + m_pthis = right.m_pthis; +#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + m_pStaticFunction = right.m_pStaticFunction; +#endif + } +}; + + +// ClosurePtr<> +// +// A private wrapper class that adds function signatures to DelegateMemento. +// It's the class that does most of the actual work. +// The signatures are specified by: +// GenericMemFunc: must be a type of GenericClass member function pointer. +// StaticFuncPtr: must be a type of function pointer with the same signature +// as GenericMemFunc. +// UnvoidStaticFuncPtr: is the same as StaticFuncPtr, except on VC6 +// where it never returns void (returns DefaultVoid instead). + +// An outer class, FastDelegateN<>, handles the invoking and creates the +// necessary typedefs. +// This class does everything else. + +namespace detail { + +template < class GenericMemFunc, class StaticFuncPtr, class UnvoidStaticFuncPtr> +class ClosurePtr : public DelegateMemento { +public: + // These functions are for setting the delegate to a member function. + + // Here's the clever bit: we convert an arbitrary member function into a + // standard form. XMemFunc should be a member function of class X, but I can't + // enforce that here. It needs to be enforced by the wrapper class. + template < class X, class XMemFunc > + inline void bindmemfunc(X *pthis, XMemFunc function_to_bind ) { + m_pthis = SimplifyMemFunc< sizeof(function_to_bind) > + ::Convert(pthis, function_to_bind, m_pFunction); +#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + m_pStaticFunction = 0; +#endif + } + // For const member functions, we only need a const class pointer. + // Since we know that the member function is const, it's safe to + // remove the const qualifier from the 'this' pointer with a const_cast. + // VC6 has problems if we just overload 'bindmemfunc', so we give it a different name. + template < class X, class XMemFunc> + inline void bindconstmemfunc(const X *pthis, XMemFunc function_to_bind) { + m_pthis= SimplifyMemFunc< sizeof(function_to_bind) > + ::Convert(const_cast(pthis), function_to_bind, m_pFunction); +#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + m_pStaticFunction = 0; +#endif + } +#ifdef FASTDELEGATE_GCC_BUG_8271 // At present, GCC doesn't recognize constness of MFPs in templates + template < class X, class XMemFunc> + inline void bindmemfunc(const X *pthis, XMemFunc function_to_bind) { + bindconstmemfunc(pthis, function_to_bind); +#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + m_pStaticFunction = 0; +#endif + } +#endif + // These functions are required for invoking the stored function + inline GenericClass *GetClosureThis() const { return m_pthis; } + inline GenericMemFunc GetClosureMemPtr() const { return reinterpret_cast(m_pFunction); } + +// There are a few ways of dealing with static function pointers. +// There's a standard-compliant, but tricky method. +// There's also a straightforward hack, that won't work on DOS compilers using the +// medium memory model. It's so evil that I can't recommend it, but I've +// implemented it anyway because it produces very nice asm code. + +#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + +// ClosurePtr<> - Safe version +// +// This implementation is standard-compliant, but a bit tricky. +// I store the function pointer inside the class, and the delegate then +// points to itself. Whenever the delegate is copied, these self-references +// must be transformed, and this complicates the = and == operators. +public: + // The next two functions are for operator ==, =, and the copy constructor. + // We may need to convert the m_pthis pointers, so that + // they remain as self-references. + template< class DerivedClass > + inline void CopyFrom (DerivedClass *pParent, const DelegateMemento &x) { + SetMementoFrom(x); + if (m_pStaticFunction!=0) { + // transform self references... + m_pthis=reinterpret_cast(pParent); + } + } + // For static functions, the 'static_function_invoker' class in the parent + // will be called. The parent then needs to call GetStaticFunction() to find out + // the actual function to invoke. + template < class DerivedClass, class ParentInvokerSig > + inline void bindstaticfunc(DerivedClass *pParent, ParentInvokerSig static_function_invoker, + StaticFuncPtr function_to_bind ) { + if (function_to_bind==0) { // cope with assignment to 0 + m_pFunction=0; + } else { + bindmemfunc(pParent, static_function_invoker); + } + m_pStaticFunction=reinterpret_cast(function_to_bind); + } + inline UnvoidStaticFuncPtr GetStaticFunction() const { + return reinterpret_cast(m_pStaticFunction); + } +#else + +// ClosurePtr<> - Evil version +// +// For compilers where data pointers are at least as big as code pointers, it is +// possible to store the function pointer in the this pointer, using another +// horrible_cast. Invocation isn't any faster, but it saves 4 bytes, and +// speeds up comparison and assignment. If C++ provided direct language support +// for delegates, they would produce asm code that was almost identical to this. +// Note that the Sun C++ and MSVC documentation explicitly state that they +// support static_cast between void * and function pointers. + + template< class DerivedClass > + inline void CopyFrom (DerivedClass *pParent, const DelegateMemento &right) { + SetMementoFrom(right); + } + // For static functions, the 'static_function_invoker' class in the parent + // will be called. The parent then needs to call GetStaticFunction() to find out + // the actual function to invoke. + // ******** EVIL, EVIL CODE! ******* + template < class DerivedClass, class ParentInvokerSig> + inline void bindstaticfunc(DerivedClass *pParent, ParentInvokerSig static_function_invoker, + StaticFuncPtr function_to_bind) { + if (function_to_bind==0) { // cope with assignment to 0 + m_pFunction=0; + } else { + // We'll be ignoring the 'this' pointer, but we need to make sure we pass + // a valid value to bindmemfunc(). + bindmemfunc(pParent, static_function_invoker); + } + + // WARNING! Evil hack. We store the function in the 'this' pointer! + // Ensure that there's a compilation failure if function pointers + // and data pointers have different sizes. + // If you get this error, you need to #undef FASTDELEGATE_USESTATICFUNCTIONHACK. + typedef int ERROR_CantUseEvilMethod[sizeof(GenericClass *)==sizeof(function_to_bind) ? 1 : -1]; + m_pthis = horrible_cast(function_to_bind); + // MSVC, SunC++ and DMC accept the following (non-standard) code: +// m_pthis = static_cast(static_cast(function_to_bind)); + // BCC32, Comeau and DMC accept this method. MSVC7.1 needs __int64 instead of long +// m_pthis = reinterpret_cast(reinterpret_cast(function_to_bind)); + } + // ******** EVIL, EVIL CODE! ******* + // This function will be called with an invalid 'this' pointer!! + // We're just returning the 'this' pointer, converted into + // a function pointer! + inline UnvoidStaticFuncPtr GetStaticFunction() const { + // Ensure that there's a compilation failure if function pointers + // and data pointers have different sizes. + // If you get this error, you need to #undef FASTDELEGATE_USESTATICFUNCTIONHACK. + typedef int ERROR_CantUseEvilMethod[sizeof(UnvoidStaticFuncPtr)==sizeof(this) ? 1 : -1]; + return horrible_cast(this); + } +#endif // !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + + // Does the closure contain this static function? + inline bool IsEqualToStaticFuncPtr(StaticFuncPtr funcptr){ + if (funcptr==0) return empty(); + // For the Evil method, if it doesn't actually contain a static function, this will return an arbitrary + // value that is not equal to any valid function pointer. + else return funcptr==reinterpret_cast(GetStaticFunction()); + } +}; + + +} // namespace detail + +//////////////////////////////////////////////////////////////////////////////// +// Fast Delegates, part 3: +// +// Wrapper classes to ensure type safety +// +//////////////////////////////////////////////////////////////////////////////// + + +// Once we have the member function conversion templates, it's easy to make the +// wrapper classes. So that they will work with as many compilers as possible, +// the classes are of the form +// FastDelegate3 +// They can cope with any combination of parameters. The max number of parameters +// allowed is 8, but it is trivial to increase this limit. +// Note that we need to treat const member functions seperately. +// All this class does is to enforce type safety, and invoke the delegate with +// the correct list of parameters. + +// Because of the weird rule about the class of derived member function pointers, +// you sometimes need to apply a downcast to the 'this' pointer. +// This is the reason for the use of "implicit_cast(pthis)" in the code below. +// If CDerivedClass is derived from CBaseClass, but doesn't override SimpleVirtualFunction, +// without this trick you'd need to write: +// MyDelegate(static_cast(&d), &CDerivedClass::SimpleVirtualFunction); +// but with the trick you can write +// MyDelegate(&d, &CDerivedClass::SimpleVirtualFunction); + +// RetType is the type the compiler uses in compiling the template. For VC6, +// it cannot be void. DesiredRetType is the real type which is returned from +// all of the functions. It can be void. + +// Implicit conversion to "bool" is achieved using the safe_bool idiom, +// using member data pointers (MDP). This allows "if (dg)..." syntax +// Because some compilers (eg codeplay) don't have a unique value for a zero +// MDP, an extra padding member is added to the SafeBool struct. +// Some compilers (eg VC6) won't implicitly convert from 0 to an MDP, so +// in that case the static function constructor is not made explicit; this +// allows "if (dg==0) ..." to compile. + +//N=0 +template +class FastDelegate0 { +private: + typedef typename detail::DefaultVoidToVoid::type DesiredRetType; + typedef DesiredRetType (*StaticFunctionPtr)(); + typedef RetType (*UnvoidStaticFunctionPtr)(); + typedef RetType (detail::GenericClass::*GenericMemFn)(); + typedef detail::ClosurePtr ClosureType; + ClosureType m_Closure; +public: + // Typedefs to aid generic programming + typedef FastDelegate0 type; + + // Construction and comparison functions + FastDelegate0() { clear(); } + FastDelegate0(const FastDelegate0 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + void operator = (const FastDelegate0 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + bool operator ==(const FastDelegate0 &x) const { + return m_Closure.IsEqual(x.m_Closure); } + bool operator !=(const FastDelegate0 &x) const { + return !m_Closure.IsEqual(x.m_Closure); } + bool operator <(const FastDelegate0 &x) const { + return m_Closure.IsLess(x.m_Closure); } + bool operator >(const FastDelegate0 &x) const { + return x.m_Closure.IsLess(m_Closure); } + // Binding to non-const member functions + template < class X, class Y > + FastDelegate0(Y *pthis, DesiredRetType (X::* function_to_bind)() ) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)()) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Binding to const member functions. + template < class X, class Y > + FastDelegate0(const Y *pthis, DesiredRetType (X::* function_to_bind)() const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)() const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Static functions. We convert them into a member function call. + // This constructor also provides implicit conversion + FastDelegate0(DesiredRetType (*function_to_bind)() ) { + bind(function_to_bind); } + // for efficiency, prevent creation of a temporary + void operator = (DesiredRetType (*function_to_bind)() ) { + bind(function_to_bind); } + inline void bind(DesiredRetType (*function_to_bind)()) { + m_Closure.bindstaticfunc(this, &FastDelegate0::InvokeStaticFunction, + function_to_bind); } + // Invoke the delegate + RetType operator() () const { + return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(); } + // Implicit conversion to "bool" using the safe_bool idiom +private: + typedef struct SafeBoolStruct { + int a_data_pointer_to_this_is_0_on_buggy_compilers; + StaticFunctionPtr m_nonzero; + } UselessTypedef; + typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; +public: + operator unspecified_bool_type() const { + return empty()? 0: &SafeBoolStruct::m_nonzero; + } + // necessary to allow ==0 to work despite the safe_bool idiom + inline bool operator==(StaticFunctionPtr funcptr) { + return m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator!=(StaticFunctionPtr funcptr) { + return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator ! () const { // Is it bound to anything? + return !m_Closure; } + inline bool empty() const { + return !m_Closure; } + void clear() { m_Closure.clear();} + // Conversion to and from the DelegateMemento storage class + const DelegateMemento & GetMemento() { return m_Closure; } + void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } + +private: // Invoker for static functions + RetType InvokeStaticFunction() const { + return (*(m_Closure.GetStaticFunction()))(); } +}; + +//N=1 +template +class FastDelegate1 { +private: + typedef typename detail::DefaultVoidToVoid::type DesiredRetType; + typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1); + typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1); + typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1); + typedef detail::ClosurePtr ClosureType; + ClosureType m_Closure; +public: + // Typedefs to aid generic programming + typedef FastDelegate1 type; + + // Construction and comparison functions + FastDelegate1() { clear(); } + FastDelegate1(const FastDelegate1 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + void operator = (const FastDelegate1 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + bool operator ==(const FastDelegate1 &x) const { + return m_Closure.IsEqual(x.m_Closure); } + bool operator !=(const FastDelegate1 &x) const { + return !m_Closure.IsEqual(x.m_Closure); } + bool operator <(const FastDelegate1 &x) const { + return m_Closure.IsLess(x.m_Closure); } + bool operator >(const FastDelegate1 &x) const { + return x.m_Closure.IsLess(m_Closure); } + // Binding to non-const member functions + template < class X, class Y > + FastDelegate1(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1) ) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1)) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Binding to const member functions. + template < class X, class Y > + FastDelegate1(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Static functions. We convert them into a member function call. + // This constructor also provides implicit conversion + FastDelegate1(DesiredRetType (*function_to_bind)(Param1 p1) ) { + bind(function_to_bind); } + // for efficiency, prevent creation of a temporary + void operator = (DesiredRetType (*function_to_bind)(Param1 p1) ) { + bind(function_to_bind); } + inline void bind(DesiredRetType (*function_to_bind)(Param1 p1)) { + m_Closure.bindstaticfunc(this, &FastDelegate1::InvokeStaticFunction, + function_to_bind); } + // Invoke the delegate + RetType operator() (Param1 p1) const { + return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1); } + // Implicit conversion to "bool" using the safe_bool idiom +private: + typedef struct SafeBoolStruct { + int a_data_pointer_to_this_is_0_on_buggy_compilers; + StaticFunctionPtr m_nonzero; + } UselessTypedef; + typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; +public: + operator unspecified_bool_type() const { + return empty()? 0: &SafeBoolStruct::m_nonzero; + } + // necessary to allow ==0 to work despite the safe_bool idiom + inline bool operator==(StaticFunctionPtr funcptr) { + return m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator!=(StaticFunctionPtr funcptr) { + return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator ! () const { // Is it bound to anything? + return !m_Closure; } + inline bool empty() const { + return !m_Closure; } + void clear() { m_Closure.clear();} + // Conversion to and from the DelegateMemento storage class + const DelegateMemento & GetMemento() { return m_Closure; } + void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } + +private: // Invoker for static functions + RetType InvokeStaticFunction(Param1 p1) const { + return (*(m_Closure.GetStaticFunction()))(p1); } +}; + +//N=2 +template +class FastDelegate2 { +private: + typedef typename detail::DefaultVoidToVoid::type DesiredRetType; + typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2); + typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2); + typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2); + typedef detail::ClosurePtr ClosureType; + ClosureType m_Closure; +public: + // Typedefs to aid generic programming + typedef FastDelegate2 type; + + // Construction and comparison functions + FastDelegate2() { clear(); } + FastDelegate2(const FastDelegate2 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + void operator = (const FastDelegate2 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + bool operator ==(const FastDelegate2 &x) const { + return m_Closure.IsEqual(x.m_Closure); } + bool operator !=(const FastDelegate2 &x) const { + return !m_Closure.IsEqual(x.m_Closure); } + bool operator <(const FastDelegate2 &x) const { + return m_Closure.IsLess(x.m_Closure); } + bool operator >(const FastDelegate2 &x) const { + return x.m_Closure.IsLess(m_Closure); } + // Binding to non-const member functions + template < class X, class Y > + FastDelegate2(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2) ) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2)) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Binding to const member functions. + template < class X, class Y > + FastDelegate2(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Static functions. We convert them into a member function call. + // This constructor also provides implicit conversion + FastDelegate2(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2) ) { + bind(function_to_bind); } + // for efficiency, prevent creation of a temporary + void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2) ) { + bind(function_to_bind); } + inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2)) { + m_Closure.bindstaticfunc(this, &FastDelegate2::InvokeStaticFunction, + function_to_bind); } + // Invoke the delegate + RetType operator() (Param1 p1, Param2 p2) const { + return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2); } + // Implicit conversion to "bool" using the safe_bool idiom +private: + typedef struct SafeBoolStruct { + int a_data_pointer_to_this_is_0_on_buggy_compilers; + StaticFunctionPtr m_nonzero; + } UselessTypedef; + typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; +public: + operator unspecified_bool_type() const { + return empty()? 0: &SafeBoolStruct::m_nonzero; + } + // necessary to allow ==0 to work despite the safe_bool idiom + inline bool operator==(StaticFunctionPtr funcptr) { + return m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator!=(StaticFunctionPtr funcptr) { + return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator ! () const { // Is it bound to anything? + return !m_Closure; } + inline bool empty() const { + return !m_Closure; } + void clear() { m_Closure.clear();} + // Conversion to and from the DelegateMemento storage class + const DelegateMemento & GetMemento() { return m_Closure; } + void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } + +private: // Invoker for static functions + RetType InvokeStaticFunction(Param1 p1, Param2 p2) const { + return (*(m_Closure.GetStaticFunction()))(p1, p2); } +}; + +//N=3 +template +class FastDelegate3 { +private: + typedef typename detail::DefaultVoidToVoid::type DesiredRetType; + typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3); + typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3); + typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3); + typedef detail::ClosurePtr ClosureType; + ClosureType m_Closure; +public: + // Typedefs to aid generic programming + typedef FastDelegate3 type; + + // Construction and comparison functions + FastDelegate3() { clear(); } + FastDelegate3(const FastDelegate3 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + void operator = (const FastDelegate3 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + bool operator ==(const FastDelegate3 &x) const { + return m_Closure.IsEqual(x.m_Closure); } + bool operator !=(const FastDelegate3 &x) const { + return !m_Closure.IsEqual(x.m_Closure); } + bool operator <(const FastDelegate3 &x) const { + return m_Closure.IsLess(x.m_Closure); } + bool operator >(const FastDelegate3 &x) const { + return x.m_Closure.IsLess(m_Closure); } + // Binding to non-const member functions + template < class X, class Y > + FastDelegate3(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3) ) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3)) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Binding to const member functions. + template < class X, class Y > + FastDelegate3(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Static functions. We convert them into a member function call. + // This constructor also provides implicit conversion + FastDelegate3(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3) ) { + bind(function_to_bind); } + // for efficiency, prevent creation of a temporary + void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3) ) { + bind(function_to_bind); } + inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3)) { + m_Closure.bindstaticfunc(this, &FastDelegate3::InvokeStaticFunction, + function_to_bind); } + // Invoke the delegate + RetType operator() (Param1 p1, Param2 p2, Param3 p3) const { + return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3); } + // Implicit conversion to "bool" using the safe_bool idiom +private: + typedef struct SafeBoolStruct { + int a_data_pointer_to_this_is_0_on_buggy_compilers; + StaticFunctionPtr m_nonzero; + } UselessTypedef; + typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; +public: + operator unspecified_bool_type() const { + return empty()? 0: &SafeBoolStruct::m_nonzero; + } + // necessary to allow ==0 to work despite the safe_bool idiom + inline bool operator==(StaticFunctionPtr funcptr) { + return m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator!=(StaticFunctionPtr funcptr) { + return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator ! () const { // Is it bound to anything? + return !m_Closure; } + inline bool empty() const { + return !m_Closure; } + void clear() { m_Closure.clear();} + // Conversion to and from the DelegateMemento storage class + const DelegateMemento & GetMemento() { return m_Closure; } + void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } + +private: // Invoker for static functions + RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3) const { + return (*(m_Closure.GetStaticFunction()))(p1, p2, p3); } +}; + +//N=4 +template +class FastDelegate4 { +private: + typedef typename detail::DefaultVoidToVoid::type DesiredRetType; + typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4); + typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4); + typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3, Param4 p4); + typedef detail::ClosurePtr ClosureType; + ClosureType m_Closure; +public: + // Typedefs to aid generic programming + typedef FastDelegate4 type; + + // Construction and comparison functions + FastDelegate4() { clear(); } + FastDelegate4(const FastDelegate4 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + void operator = (const FastDelegate4 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + bool operator ==(const FastDelegate4 &x) const { + return m_Closure.IsEqual(x.m_Closure); } + bool operator !=(const FastDelegate4 &x) const { + return !m_Closure.IsEqual(x.m_Closure); } + bool operator <(const FastDelegate4 &x) const { + return m_Closure.IsLess(x.m_Closure); } + bool operator >(const FastDelegate4 &x) const { + return x.m_Closure.IsLess(m_Closure); } + // Binding to non-const member functions + template < class X, class Y > + FastDelegate4(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4) ) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4)) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Binding to const member functions. + template < class X, class Y > + FastDelegate4(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Static functions. We convert them into a member function call. + // This constructor also provides implicit conversion + FastDelegate4(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4) ) { + bind(function_to_bind); } + // for efficiency, prevent creation of a temporary + void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4) ) { + bind(function_to_bind); } + inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4)) { + m_Closure.bindstaticfunc(this, &FastDelegate4::InvokeStaticFunction, + function_to_bind); } + // Invoke the delegate + RetType operator() (Param1 p1, Param2 p2, Param3 p3, Param4 p4) const { + return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3, p4); } + // Implicit conversion to "bool" using the safe_bool idiom +private: + typedef struct SafeBoolStruct { + int a_data_pointer_to_this_is_0_on_buggy_compilers; + StaticFunctionPtr m_nonzero; + } UselessTypedef; + typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; +public: + operator unspecified_bool_type() const { + return empty()? 0: &SafeBoolStruct::m_nonzero; + } + // necessary to allow ==0 to work despite the safe_bool idiom + inline bool operator==(StaticFunctionPtr funcptr) { + return m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator!=(StaticFunctionPtr funcptr) { + return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator ! () const { // Is it bound to anything? + return !m_Closure; } + inline bool empty() const { + return !m_Closure; } + void clear() { m_Closure.clear();} + // Conversion to and from the DelegateMemento storage class + const DelegateMemento & GetMemento() { return m_Closure; } + void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } + +private: // Invoker for static functions + RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3, Param4 p4) const { + return (*(m_Closure.GetStaticFunction()))(p1, p2, p3, p4); } +}; + +//N=5 +template +class FastDelegate5 { +private: + typedef typename detail::DefaultVoidToVoid::type DesiredRetType; + typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5); + typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5); + typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5); + typedef detail::ClosurePtr ClosureType; + ClosureType m_Closure; +public: + // Typedefs to aid generic programming + typedef FastDelegate5 type; + + // Construction and comparison functions + FastDelegate5() { clear(); } + FastDelegate5(const FastDelegate5 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + void operator = (const FastDelegate5 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + bool operator ==(const FastDelegate5 &x) const { + return m_Closure.IsEqual(x.m_Closure); } + bool operator !=(const FastDelegate5 &x) const { + return !m_Closure.IsEqual(x.m_Closure); } + bool operator <(const FastDelegate5 &x) const { + return m_Closure.IsLess(x.m_Closure); } + bool operator >(const FastDelegate5 &x) const { + return x.m_Closure.IsLess(m_Closure); } + // Binding to non-const member functions + template < class X, class Y > + FastDelegate5(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) ) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5)) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Binding to const member functions. + template < class X, class Y > + FastDelegate5(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Static functions. We convert them into a member function call. + // This constructor also provides implicit conversion + FastDelegate5(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) ) { + bind(function_to_bind); } + // for efficiency, prevent creation of a temporary + void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) ) { + bind(function_to_bind); } + inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5)) { + m_Closure.bindstaticfunc(this, &FastDelegate5::InvokeStaticFunction, + function_to_bind); } + // Invoke the delegate + RetType operator() (Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) const { + return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3, p4, p5); } + // Implicit conversion to "bool" using the safe_bool idiom +private: + typedef struct SafeBoolStruct { + int a_data_pointer_to_this_is_0_on_buggy_compilers; + StaticFunctionPtr m_nonzero; + } UselessTypedef; + typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; +public: + operator unspecified_bool_type() const { + return empty()? 0: &SafeBoolStruct::m_nonzero; + } + // necessary to allow ==0 to work despite the safe_bool idiom + inline bool operator==(StaticFunctionPtr funcptr) { + return m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator!=(StaticFunctionPtr funcptr) { + return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator ! () const { // Is it bound to anything? + return !m_Closure; } + inline bool empty() const { + return !m_Closure; } + void clear() { m_Closure.clear();} + // Conversion to and from the DelegateMemento storage class + const DelegateMemento & GetMemento() { return m_Closure; } + void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } + +private: // Invoker for static functions + RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) const { + return (*(m_Closure.GetStaticFunction()))(p1, p2, p3, p4, p5); } +}; + +//N=6 +template +class FastDelegate6 { +private: + typedef typename detail::DefaultVoidToVoid::type DesiredRetType; + typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6); + typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6); + typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6); + typedef detail::ClosurePtr ClosureType; + ClosureType m_Closure; +public: + // Typedefs to aid generic programming + typedef FastDelegate6 type; + + // Construction and comparison functions + FastDelegate6() { clear(); } + FastDelegate6(const FastDelegate6 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + void operator = (const FastDelegate6 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + bool operator ==(const FastDelegate6 &x) const { + return m_Closure.IsEqual(x.m_Closure); } + bool operator !=(const FastDelegate6 &x) const { + return !m_Closure.IsEqual(x.m_Closure); } + bool operator <(const FastDelegate6 &x) const { + return m_Closure.IsLess(x.m_Closure); } + bool operator >(const FastDelegate6 &x) const { + return x.m_Closure.IsLess(m_Closure); } + // Binding to non-const member functions + template < class X, class Y > + FastDelegate6(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) ) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6)) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Binding to const member functions. + template < class X, class Y > + FastDelegate6(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Static functions. We convert them into a member function call. + // This constructor also provides implicit conversion + FastDelegate6(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) ) { + bind(function_to_bind); } + // for efficiency, prevent creation of a temporary + void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) ) { + bind(function_to_bind); } + inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6)) { + m_Closure.bindstaticfunc(this, &FastDelegate6::InvokeStaticFunction, + function_to_bind); } + // Invoke the delegate + RetType operator() (Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) const { + return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3, p4, p5, p6); } + // Implicit conversion to "bool" using the safe_bool idiom +private: + typedef struct SafeBoolStruct { + int a_data_pointer_to_this_is_0_on_buggy_compilers; + StaticFunctionPtr m_nonzero; + } UselessTypedef; + typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; +public: + operator unspecified_bool_type() const { + return empty()? 0: &SafeBoolStruct::m_nonzero; + } + // necessary to allow ==0 to work despite the safe_bool idiom + inline bool operator==(StaticFunctionPtr funcptr) { + return m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator!=(StaticFunctionPtr funcptr) { + return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator ! () const { // Is it bound to anything? + return !m_Closure; } + inline bool empty() const { + return !m_Closure; } + void clear() { m_Closure.clear();} + // Conversion to and from the DelegateMemento storage class + const DelegateMemento & GetMemento() { return m_Closure; } + void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } + +private: // Invoker for static functions + RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) const { + return (*(m_Closure.GetStaticFunction()))(p1, p2, p3, p4, p5, p6); } +}; + +//N=7 +template +class FastDelegate7 { +private: + typedef typename detail::DefaultVoidToVoid::type DesiredRetType; + typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7); + typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7); + typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7); + typedef detail::ClosurePtr ClosureType; + ClosureType m_Closure; +public: + // Typedefs to aid generic programming + typedef FastDelegate7 type; + + // Construction and comparison functions + FastDelegate7() { clear(); } + FastDelegate7(const FastDelegate7 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + void operator = (const FastDelegate7 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + bool operator ==(const FastDelegate7 &x) const { + return m_Closure.IsEqual(x.m_Closure); } + bool operator !=(const FastDelegate7 &x) const { + return !m_Closure.IsEqual(x.m_Closure); } + bool operator <(const FastDelegate7 &x) const { + return m_Closure.IsLess(x.m_Closure); } + bool operator >(const FastDelegate7 &x) const { + return x.m_Closure.IsLess(m_Closure); } + // Binding to non-const member functions + template < class X, class Y > + FastDelegate7(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) ) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7)) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Binding to const member functions. + template < class X, class Y > + FastDelegate7(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Static functions. We convert them into a member function call. + // This constructor also provides implicit conversion + FastDelegate7(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) ) { + bind(function_to_bind); } + // for efficiency, prevent creation of a temporary + void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) ) { + bind(function_to_bind); } + inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7)) { + m_Closure.bindstaticfunc(this, &FastDelegate7::InvokeStaticFunction, + function_to_bind); } + // Invoke the delegate + RetType operator() (Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) const { + return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3, p4, p5, p6, p7); } + // Implicit conversion to "bool" using the safe_bool idiom +private: + typedef struct SafeBoolStruct { + int a_data_pointer_to_this_is_0_on_buggy_compilers; + StaticFunctionPtr m_nonzero; + } UselessTypedef; + typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; +public: + operator unspecified_bool_type() const { + return empty()? 0: &SafeBoolStruct::m_nonzero; + } + // necessary to allow ==0 to work despite the safe_bool idiom + inline bool operator==(StaticFunctionPtr funcptr) { + return m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator!=(StaticFunctionPtr funcptr) { + return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator ! () const { // Is it bound to anything? + return !m_Closure; } + inline bool empty() const { + return !m_Closure; } + void clear() { m_Closure.clear();} + // Conversion to and from the DelegateMemento storage class + const DelegateMemento & GetMemento() { return m_Closure; } + void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } + +private: // Invoker for static functions + RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) const { + return (*(m_Closure.GetStaticFunction()))(p1, p2, p3, p4, p5, p6, p7); } +}; + +//N=8 +template +class FastDelegate8 { +private: + typedef typename detail::DefaultVoidToVoid::type DesiredRetType; + typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8); + typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8); + typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8); + typedef detail::ClosurePtr ClosureType; + ClosureType m_Closure; +public: + // Typedefs to aid generic programming + typedef FastDelegate8 type; + + // Construction and comparison functions + FastDelegate8() { clear(); } + FastDelegate8(const FastDelegate8 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + void operator = (const FastDelegate8 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + bool operator ==(const FastDelegate8 &x) const { + return m_Closure.IsEqual(x.m_Closure); } + bool operator !=(const FastDelegate8 &x) const { + return !m_Closure.IsEqual(x.m_Closure); } + bool operator <(const FastDelegate8 &x) const { + return m_Closure.IsLess(x.m_Closure); } + bool operator >(const FastDelegate8 &x) const { + return x.m_Closure.IsLess(m_Closure); } + // Binding to non-const member functions + template < class X, class Y > + FastDelegate8(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) ) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8)) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Binding to const member functions. + template < class X, class Y > + FastDelegate8(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Static functions. We convert them into a member function call. + // This constructor also provides implicit conversion + FastDelegate8(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) ) { + bind(function_to_bind); } + // for efficiency, prevent creation of a temporary + void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) ) { + bind(function_to_bind); } + inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8)) { + m_Closure.bindstaticfunc(this, &FastDelegate8::InvokeStaticFunction, + function_to_bind); } + // Invoke the delegate + RetType operator() (Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) const { + return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3, p4, p5, p6, p7, p8); } + // Implicit conversion to "bool" using the safe_bool idiom +private: + typedef struct SafeBoolStruct { + int a_data_pointer_to_this_is_0_on_buggy_compilers; + StaticFunctionPtr m_nonzero; + } UselessTypedef; + typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; +public: + operator unspecified_bool_type() const { + return empty()? 0: &SafeBoolStruct::m_nonzero; + } + // necessary to allow ==0 to work despite the safe_bool idiom + inline bool operator==(StaticFunctionPtr funcptr) { + return m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator!=(StaticFunctionPtr funcptr) { + return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator ! () const { // Is it bound to anything? + return !m_Closure; } + inline bool empty() const { + return !m_Closure; } + void clear() { m_Closure.clear();} + // Conversion to and from the DelegateMemento storage class + const DelegateMemento & GetMemento() { return m_Closure; } + void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } + +private: // Invoker for static functions + RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) const { + return (*(m_Closure.GetStaticFunction()))(p1, p2, p3, p4, p5, p6, p7, p8); } +}; + + +//////////////////////////////////////////////////////////////////////////////// +// Fast Delegates, part 4: +// +// FastDelegate<> class (Original author: Jody Hagins) +// Allows boost::function style syntax like: +// FastDelegate< double (int, long) > +// instead of: +// FastDelegate2< int, long, double > +// +//////////////////////////////////////////////////////////////////////////////// + +#ifdef FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX + +// Declare FastDelegate as a class template. It will be specialized +// later for all number of arguments. +template +class FastDelegate; + +//N=0 +// Specialization to allow use of +// FastDelegate< R ( ) > +// instead of +// FastDelegate0 < R > +template +class FastDelegate< R ( ) > + // Inherit from FastDelegate0 so that it can be treated just like a FastDelegate0 + : public FastDelegate0 < R > +{ +public: + // Make using the base type a bit easier via typedef. + typedef FastDelegate0 < R > BaseType; + + // Allow users access to the specific type of this delegate. + typedef FastDelegate SelfType; + + // Mimic the base class constructors. + FastDelegate() : BaseType() { } + + template < class X, class Y > + FastDelegate(Y * pthis, + R (X::* function_to_bind)( )) + : BaseType(pthis, function_to_bind) { } + + template < class X, class Y > + FastDelegate(const Y *pthis, + R (X::* function_to_bind)( ) const) + : BaseType(pthis, function_to_bind) + { } + + FastDelegate(R (*function_to_bind)( )) + : BaseType(function_to_bind) { } + void operator = (const BaseType &x) { + *static_cast(this) = x; } +}; + +//N=1 +// Specialization to allow use of +// FastDelegate< R ( Param1 ) > +// instead of +// FastDelegate1 < Param1, R > +template +class FastDelegate< R ( Param1 ) > + // Inherit from FastDelegate1 so that it can be treated just like a FastDelegate1 + : public FastDelegate1 < Param1, R > +{ +public: + // Make using the base type a bit easier via typedef. + typedef FastDelegate1 < Param1, R > BaseType; + + // Allow users access to the specific type of this delegate. + typedef FastDelegate SelfType; + + // Mimic the base class constructors. + FastDelegate() : BaseType() { } + + template < class X, class Y > + FastDelegate(Y * pthis, + R (X::* function_to_bind)( Param1 p1 )) + : BaseType(pthis, function_to_bind) { } + + template < class X, class Y > + FastDelegate(const Y *pthis, + R (X::* function_to_bind)( Param1 p1 ) const) + : BaseType(pthis, function_to_bind) + { } + + FastDelegate(R (*function_to_bind)( Param1 p1 )) + : BaseType(function_to_bind) { } + void operator = (const BaseType &x) { + *static_cast(this) = x; } +}; + +//N=2 +// Specialization to allow use of +// FastDelegate< R ( Param1, Param2 ) > +// instead of +// FastDelegate2 < Param1, Param2, R > +template +class FastDelegate< R ( Param1, Param2 ) > + // Inherit from FastDelegate2 so that it can be treated just like a FastDelegate2 + : public FastDelegate2 < Param1, Param2, R > +{ +public: + // Make using the base type a bit easier via typedef. + typedef FastDelegate2 < Param1, Param2, R > BaseType; + + // Allow users access to the specific type of this delegate. + typedef FastDelegate SelfType; + + // Mimic the base class constructors. + FastDelegate() : BaseType() { } + + template < class X, class Y > + FastDelegate(Y * pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2 )) + : BaseType(pthis, function_to_bind) { } + + template < class X, class Y > + FastDelegate(const Y *pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2 ) const) + : BaseType(pthis, function_to_bind) + { } + + FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2 )) + : BaseType(function_to_bind) { } + void operator = (const BaseType &x) { + *static_cast(this) = x; } +}; + +//N=3 +// Specialization to allow use of +// FastDelegate< R ( Param1, Param2, Param3 ) > +// instead of +// FastDelegate3 < Param1, Param2, Param3, R > +template +class FastDelegate< R ( Param1, Param2, Param3 ) > + // Inherit from FastDelegate3 so that it can be treated just like a FastDelegate3 + : public FastDelegate3 < Param1, Param2, Param3, R > +{ +public: + // Make using the base type a bit easier via typedef. + typedef FastDelegate3 < Param1, Param2, Param3, R > BaseType; + + // Allow users access to the specific type of this delegate. + typedef FastDelegate SelfType; + + // Mimic the base class constructors. + FastDelegate() : BaseType() { } + + template < class X, class Y > + FastDelegate(Y * pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3 )) + : BaseType(pthis, function_to_bind) { } + + template < class X, class Y > + FastDelegate(const Y *pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3 ) const) + : BaseType(pthis, function_to_bind) + { } + + FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3 )) + : BaseType(function_to_bind) { } + void operator = (const BaseType &x) { + *static_cast(this) = x; } +}; + +//N=4 +// Specialization to allow use of +// FastDelegate< R ( Param1, Param2, Param3, Param4 ) > +// instead of +// FastDelegate4 < Param1, Param2, Param3, Param4, R > +template +class FastDelegate< R ( Param1, Param2, Param3, Param4 ) > + // Inherit from FastDelegate4 so that it can be treated just like a FastDelegate4 + : public FastDelegate4 < Param1, Param2, Param3, Param4, R > +{ +public: + // Make using the base type a bit easier via typedef. + typedef FastDelegate4 < Param1, Param2, Param3, Param4, R > BaseType; + + // Allow users access to the specific type of this delegate. + typedef FastDelegate SelfType; + + // Mimic the base class constructors. + FastDelegate() : BaseType() { } + + template < class X, class Y > + FastDelegate(Y * pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4 )) + : BaseType(pthis, function_to_bind) { } + + template < class X, class Y > + FastDelegate(const Y *pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) const) + : BaseType(pthis, function_to_bind) + { } + + FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4 )) + : BaseType(function_to_bind) { } + void operator = (const BaseType &x) { + *static_cast(this) = x; } +}; + +//N=5 +// Specialization to allow use of +// FastDelegate< R ( Param1, Param2, Param3, Param4, Param5 ) > +// instead of +// FastDelegate5 < Param1, Param2, Param3, Param4, Param5, R > +template +class FastDelegate< R ( Param1, Param2, Param3, Param4, Param5 ) > + // Inherit from FastDelegate5 so that it can be treated just like a FastDelegate5 + : public FastDelegate5 < Param1, Param2, Param3, Param4, Param5, R > +{ +public: + // Make using the base type a bit easier via typedef. + typedef FastDelegate5 < Param1, Param2, Param3, Param4, Param5, R > BaseType; + + // Allow users access to the specific type of this delegate. + typedef FastDelegate SelfType; + + // Mimic the base class constructors. + FastDelegate() : BaseType() { } + + template < class X, class Y > + FastDelegate(Y * pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 )) + : BaseType(pthis, function_to_bind) { } + + template < class X, class Y > + FastDelegate(const Y *pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) const) + : BaseType(pthis, function_to_bind) + { } + + FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 )) + : BaseType(function_to_bind) { } + void operator = (const BaseType &x) { + *static_cast(this) = x; } +}; + +//N=6 +// Specialization to allow use of +// FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6 ) > +// instead of +// FastDelegate6 < Param1, Param2, Param3, Param4, Param5, Param6, R > +template +class FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6 ) > + // Inherit from FastDelegate6 so that it can be treated just like a FastDelegate6 + : public FastDelegate6 < Param1, Param2, Param3, Param4, Param5, Param6, R > +{ +public: + // Make using the base type a bit easier via typedef. + typedef FastDelegate6 < Param1, Param2, Param3, Param4, Param5, Param6, R > BaseType; + + // Allow users access to the specific type of this delegate. + typedef FastDelegate SelfType; + + // Mimic the base class constructors. + FastDelegate() : BaseType() { } + + template < class X, class Y > + FastDelegate(Y * pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 )) + : BaseType(pthis, function_to_bind) { } + + template < class X, class Y > + FastDelegate(const Y *pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) const) + : BaseType(pthis, function_to_bind) + { } + + FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 )) + : BaseType(function_to_bind) { } + void operator = (const BaseType &x) { + *static_cast(this) = x; } +}; + +//N=7 +// Specialization to allow use of +// FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6, Param7 ) > +// instead of +// FastDelegate7 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, R > +template +class FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6, Param7 ) > + // Inherit from FastDelegate7 so that it can be treated just like a FastDelegate7 + : public FastDelegate7 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, R > +{ +public: + // Make using the base type a bit easier via typedef. + typedef FastDelegate7 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, R > BaseType; + + // Allow users access to the specific type of this delegate. + typedef FastDelegate SelfType; + + // Mimic the base class constructors. + FastDelegate() : BaseType() { } + + template < class X, class Y > + FastDelegate(Y * pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 )) + : BaseType(pthis, function_to_bind) { } + + template < class X, class Y > + FastDelegate(const Y *pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) const) + : BaseType(pthis, function_to_bind) + { } + + FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 )) + : BaseType(function_to_bind) { } + void operator = (const BaseType &x) { + *static_cast(this) = x; } +}; + +//N=8 +// Specialization to allow use of +// FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8 ) > +// instead of +// FastDelegate8 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, R > +template +class FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8 ) > + // Inherit from FastDelegate8 so that it can be treated just like a FastDelegate8 + : public FastDelegate8 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, R > +{ +public: + // Make using the base type a bit easier via typedef. + typedef FastDelegate8 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, R > BaseType; + + // Allow users access to the specific type of this delegate. + typedef FastDelegate SelfType; + + // Mimic the base class constructors. + FastDelegate() : BaseType() { } + + template < class X, class Y > + FastDelegate(Y * pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 )) + : BaseType(pthis, function_to_bind) { } + + template < class X, class Y > + FastDelegate(const Y *pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) const) + : BaseType(pthis, function_to_bind) + { } + + FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 )) + : BaseType(function_to_bind) { } + void operator = (const BaseType &x) { + *static_cast(this) = x; } +}; + + +#endif //FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX + +//////////////////////////////////////////////////////////////////////////////// +// Fast Delegates, part 5: +// +// MakeDelegate() helper function +// +// MakeDelegate(&x, &X::func) returns a fastdelegate of the type +// necessary for calling x.func() with the correct number of arguments. +// This makes it possible to eliminate many typedefs from user code. +// +//////////////////////////////////////////////////////////////////////////////// + +// Also declare overloads of a MakeDelegate() global function to +// reduce the need for typedefs. +// We need seperate overloads for const and non-const member functions. +// Also, because of the weird rule about the class of derived member function pointers, +// implicit downcasts may need to be applied later to the 'this' pointer. +// That's why two classes (X and Y) appear in the definitions. Y must be implicitly +// castable to X. + +// Workaround for VC6. VC6 needs void return types converted into DefaultVoid. +// GCC 3.2 and later won't compile this unless it's preceded by 'typename', +// but VC6 doesn't allow 'typename' in this context. +// So, I have to use a macro. + +#ifdef FASTDLGT_VC6 +#define FASTDLGT_RETTYPE detail::VoidToDefaultVoid::type +#else +#define FASTDLGT_RETTYPE RetType +#endif + +//N=0 +template +FastDelegate0 MakeDelegate(Y* x, RetType (X::*func)()) { + return FastDelegate0(x, func); +} + +template +FastDelegate0 MakeDelegate(Y* x, RetType (X::*func)() const) { + return FastDelegate0(x, func); +} + +//N=1 +template +FastDelegate1 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1)) { + return FastDelegate1(x, func); +} + +template +FastDelegate1 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1) const) { + return FastDelegate1(x, func); +} + +//N=2 +template +FastDelegate2 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2)) { + return FastDelegate2(x, func); +} + +template +FastDelegate2 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2) const) { + return FastDelegate2(x, func); +} + +//N=3 +template +FastDelegate3 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3)) { + return FastDelegate3(x, func); +} + +template +FastDelegate3 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3) const) { + return FastDelegate3(x, func); +} + +//N=4 +template +FastDelegate4 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4)) { + return FastDelegate4(x, func); +} + +template +FastDelegate4 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4) const) { + return FastDelegate4(x, func); +} + +//N=5 +template +FastDelegate5 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5)) { + return FastDelegate5(x, func); +} + +template +FastDelegate5 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) const) { + return FastDelegate5(x, func); +} + +//N=6 +template +FastDelegate6 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6)) { + return FastDelegate6(x, func); +} + +template +FastDelegate6 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) const) { + return FastDelegate6(x, func); +} + +//N=7 +template +FastDelegate7 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7)) { + return FastDelegate7(x, func); +} + +template +FastDelegate7 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) const) { + return FastDelegate7(x, func); +} + +//N=8 +template +FastDelegate8 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8)) { + return FastDelegate8(x, func); +} + +template +FastDelegate8 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) const) { + return FastDelegate8(x, func); +} + + + // clean up after ourselves... +#undef FASTDLGT_RETTYPE + +} // namespace fastdelegate + + +#endif // FASTDELEGATE_H \ No newline at end of file diff --git a/external/dtEntity/include/dtEntity/FastDelegateBind.h b/external/dtEntity/include/dtEntity/FastDelegateBind.h new file mode 100644 index 000000000..5a1ef4826 --- /dev/null +++ b/external/dtEntity/include/dtEntity/FastDelegateBind.h @@ -0,0 +1,245 @@ +#pragma once + +#ifndef FASTDELEGATEBIND_H +#define FASTDELEGATEBIND_H + +// FastDelegateBind.h +// Helper file for FastDelegates. Provides bind() function, enabling +// FastDelegates to be rapidly compared to programs using boost::function and boost::bind. +// +// Documentation is found at http://www.codeproject.com/cpp/FastDelegate.asp +// +// Original author: Jody Hagins. +// Minor changes by Don Clugston. +// +// Warning: The arguments to 'bind' are ignored! No actual binding is performed. +// The behaviour is equivalent to boost::bind only when the basic placeholder +// arguments _1, _2, _3, etc are used in order. +// +// HISTORY: +// 1.4 Dec 2004. Initial release as part of FastDelegate 1.4. + + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +//////////////////////////////////////////////////////////////////////////////// +// FastDelegate bind() +// +// bind() helper function for boost compatibility. +// (Original author: Jody Hagins). +// +// Add another helper, so FastDelegate can be a dropin replacement +// for boost::bind (in a fair number of cases). +// Note the elipses, because boost::bind() takes place holders +// but FastDelegate does not care about them. Getting the place holder +// mechanism to work, and play well with boost is a bit tricky, so +// we do the "easy" thing... +// Assume we have the following code... +// using boost::bind; +// bind(&Foo:func, &foo, _1, _2); +// we should be able to replace the "using" with... +// using fastdelegate::bind; +// and everything should work fine... +//////////////////////////////////////////////////////////////////////////////// + +#ifdef FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX + +namespace fastdelegate { + +//N=0 +template +FastDelegate< RetType ( ) > +bind( + RetType (X::*func)( ), + Y * y, + ...) +{ + return FastDelegate< RetType ( ) >(y, func); +} + +template +FastDelegate< RetType ( ) > +bind( + RetType (X::*func)( ) const, + Y * y, + ...) +{ + return FastDelegate< RetType ( ) >(y, func); +} + +//N=1 +template +FastDelegate< RetType ( Param1 p1 ) > +bind( + RetType (X::*func)( Param1 p1 ), + Y * y, + ...) +{ + return FastDelegate< RetType ( Param1 p1 ) >(y, func); +} + +template +FastDelegate< RetType ( Param1 p1 ) > +bind( + RetType (X::*func)( Param1 p1 ) const, + Y * y, + ...) +{ + return FastDelegate< RetType ( Param1 p1 ) >(y, func); +} + +//N=2 +template +FastDelegate< RetType ( Param1 p1, Param2 p2 ) > +bind( + RetType (X::*func)( Param1 p1, Param2 p2 ), + Y * y, + ...) +{ + return FastDelegate< RetType ( Param1 p1, Param2 p2 ) >(y, func); +} + +template +FastDelegate< RetType ( Param1 p1, Param2 p2 ) > +bind( + RetType (X::*func)( Param1 p1, Param2 p2 ) const, + Y * y, + ...) +{ + return FastDelegate< RetType ( Param1 p1, Param2 p2 ) >(y, func); +} + +//N=3 +template +FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3 ) > +bind( + RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3 ), + Y * y, + ...) +{ + return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3 ) >(y, func); +} + +template +FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3 ) > +bind( + RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3 ) const, + Y * y, + ...) +{ + return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3 ) >(y, func); +} + +//N=4 +template +FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) > +bind( + RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ), + Y * y, + ...) +{ + return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) >(y, func); +} + +template +FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) > +bind( + RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) const, + Y * y, + ...) +{ + return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) >(y, func); +} + +//N=5 +template +FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) > +bind( + RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ), + Y * y, + ...) +{ + return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) >(y, func); +} + +template +FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) > +bind( + RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) const, + Y * y, + ...) +{ + return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) >(y, func); +} + +//N=6 +template +FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) > +bind( + RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ), + Y * y, + ...) +{ + return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) >(y, func); +} + +template +FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) > +bind( + RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) const, + Y * y, + ...) +{ + return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) >(y, func); +} + +//N=7 +template +FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) > +bind( + RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ), + Y * y, + ...) +{ + return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) >(y, func); +} + +template +FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) > +bind( + RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) const, + Y * y, + ...) +{ + return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) >(y, func); +} + +//N=8 +template +FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) > +bind( + RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ), + Y * y, + ...) +{ + return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) >(y, func); +} + +template +FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) > +bind( + RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) const, + Y * y, + ...) +{ + return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) >(y, func); +} + + +#endif //FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX + +} // namespace fastdelegate + +#endif // FASTDELEGATEBIND_H \ No newline at end of file diff --git a/external/dtEntity/include/dtEntity/commandmessages.h b/external/dtEntity/include/dtEntity/commandmessages.h new file mode 100644 index 000000000..6be78fa9a --- /dev/null +++ b/external/dtEntity/include/dtEntity/commandmessages.h @@ -0,0 +1,457 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include + +namespace dtEntity +{ + + /** + * These messages can be sent by user code to trigger a reaction in + * a dtEntity subsystem. + */ + + + //////////////////////////////////////////////////////////////////////////////// + class MessageFactory; + + /** + * Adds all messages to message factory + */ + void DT_ENTITY_EXPORT RegisterCommandMessages(MessageFactory&); + + + //////////////////////////////////////////////////////////////////////////////// + /** + * Send this message to cause the map system to remove an entity from + * scene and delete it + */ + class DT_ENTITY_EXPORT DeleteEntityMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId UniqueIdId; + + DeleteEntityMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + void SetUniqueId(const std::string& v) { mUniqueId.Set(v); } + std::string GetUniqueId() const { return mUniqueId.Get(); } + + private: + + StringProperty mUniqueId; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Systems can react to this message by enabling their debug drawing. + */ + class DT_ENTITY_EXPORT EnableDebugDrawingMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId EnableId; + + EnableDebugDrawingMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + bool GetEnable() const { return mEnable.Get(); } + void SetEnable(bool v){ mEnable.Set(v); } + + private: + + BoolProperty mEnable; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Cause camera to be moved to entity + */ + class DT_ENTITY_EXPORT MoveCameraToEntityMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId AboutEntityId; + static const StringId DistanceId; + static const StringId KeepCameraDirectionId; + static const StringId ContextIdId; + + MoveCameraToEntityMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + EntityId GetAboutEntityId() const { return mAboutEntityId.Get(); } + void SetAboutEntityId(EntityId id) { mAboutEntityId.Set(id); } + + // default is 10 + double GetDistance() const { return mDistance.Get(); } + void SetDistance(double v) { mDistance.Set(v); } + + // if true: current eye direction of camera is preserved. + // if false: rotate camera from current position to target entity, then + // move until distance is reached + // true by default + bool GetKeepCameraDirection() const { return mKeepCameraDirection.Get(); } + void SetKeepCameraDirection(bool v) { mKeepCameraDirection.Set(v); } + + // camera context + int GetContextId() const { return mContextId.Get(); } + void SetContextId(int v) { mContextId.Set(v); } + + private: + + UIntProperty mAboutEntityId; + DoubleProperty mDistance; + BoolProperty mKeepCameraDirection; + IntProperty mContextId; + }; + + /////////////////////////////////////////////////////////////////////////////// + /** + * Cause camera to be moved to a specific position + */ + class DT_ENTITY_EXPORT MoveCameraToPositionMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId PositionId; + static const StringId LookAtId; + static const StringId UpId; + static const StringId ContextIdId; + + MoveCameraToPositionMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + Vec3d GetPosition() const { return mPosition.Get(); } + void SetPosition(const Vec3d& v) { mPosition.Set(v); } + + // if same as position: Look in direction of movement from last position + Vec3d GetLookAt() const { return mLookAt.Get(); } + void SetLookAt(const Vec3d& v) { mLookAt.Set(v); } + + Vec3f GetUp() const { return mUp.Get(); } + void SetUp(const Vec3f& v) { mUp.Set(v); } + + // camera context + int GetContextId() const { return mContextId.Get(); } + void SetContextId(int v) { mContextId.Set(v); } + + private: + + Vec3dProperty mPosition; + Vec3dProperty mLookAt; + Vec3Property mUp; + IntProperty mContextId; + }; + + /////////////////////////////////////////////////////////////////////////////// + /** + * Cause an animation to be played + */ + class DT_ENTITY_EXPORT PlayAnimationMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId AboutEntityId; + static const StringId AnimationNameId; + + PlayAnimationMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + EntityId GetAboutEntityId() const { return mAboutEntityId.Get(); } + void SetAboutEntityId(EntityId id) { mAboutEntityId.Set(id); } + + std::string GetAnimationName() const { return mAnimationName.Get(); } + void SetAnimationName(const std::string& id) { mAnimationName.Set(id); } + + private: + + UIntProperty mAboutEntityId; + StringProperty mAnimationName; + }; + + //////////////////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT RequestEntityDeselectMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId AboutEntityId; + + RequestEntityDeselectMessage(); + + // Create a copy of this message on the heap + virtual Message* Clone() const { return CloneContainer(); } + + void SetAboutEntityId(EntityId id) { mAboutEntity.Set(id); } + EntityId GetAboutEntityId() const { return mAboutEntity.Get(); } + + private: + + UIntProperty mAboutEntity; + }; + + //////////////////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT RequestEntitySelectMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId AboutEntityId; + static const StringId UseMultiSelectId; + + RequestEntitySelectMessage(); + + // Create a copy of this message on the heap + virtual Message* Clone() const { return CloneContainer(); } + + void SetAboutEntityId(EntityId id) { mAboutEntity.Set(id); } + EntityId GetAboutEntityId() const { return mAboutEntity.Get(); } + + void SetUseMultiSelect(bool v) { mUseMultiSelect.Set(v); } + bool GetUseMultiSelect() const { return mUseMultiSelect.Get(); } + + private: + + UIntProperty mAboutEntity; + BoolProperty mUseMultiSelect; + }; + + //////////////////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT RequestToggleEntitySelectionMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId AboutEntityId; + + RequestToggleEntitySelectionMessage(); + + // Create a copy of this message on the heap + virtual Message* Clone() const { return CloneContainer(); } + + void SetAboutEntityId(EntityId id) { mAboutEntity.Set(id); } + EntityId GetAboutEntityId() const { return mAboutEntity.Get(); } + + private: + + UIntProperty mAboutEntity; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Application system reacts to this message by retrieving a component of type t + * from entity identified by id and applying the property values of mProperty + * to the component. + */ + class DT_ENTITY_EXPORT SetComponentPropertiesMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId EntityUniqueIdId; + static const StringId ComponentTypeId; + static const StringId PropertiesId; + + SetComponentPropertiesMessage(); + + /** + * Initialize with single property. Prop is cloned! + */ + SetComponentPropertiesMessage(const std::string& entityUniqueId, + const std::string& componenttype, const std::string& propname, Property& prop); + + virtual Message* Clone() const { return CloneContainer(); } + + std::string GetEntityUniqueId() const { return mEntityUniqueId.Get(); } + void SetEntityUniqueId(const std::string& id) { mEntityUniqueId.Set(id); } + + void SetComponentType(const std::string& t) { mComponentType.Set(t); } + std::string GetComponentType() const { return mComponentType.Get(); } + + /** + * Group of properties that will be applied to entity system + */ + void SetComponentProperties(PropertyGroup& v) { mProperties.Set(v); } + const PropertyGroup& GetComponentProperties() const { return mProperties.Get(); } + + private: + StringProperty mComponentType; + GroupProperty mProperties; + StringProperty mEntityUniqueId; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Application system reacts to this message by retrieving the entity system + * of type t and applying the property values of mProperty to the entity system. + */ + class DT_ENTITY_EXPORT SetSystemPropertiesMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId ComponentTypeId; + static const StringId PropertiesId; + + SetSystemPropertiesMessage(); + + /** + * Initialize with single property. Prop is cloned! + */ + SetSystemPropertiesMessage(const std::string& componenttype, const std::string& propname, Property& prop); + + virtual Message* Clone() const { return CloneContainer(); } + + void SetComponentType(const std::string& t) { mComponentType.Set(t); } + std::string GetComponentType() const { return mComponentType.Get(); } + + /** + * Group of properties that will be applied to entity system + */ + void SetSystemProperties(PropertyGroup& v) { mProperties.Set(v); } + const PropertyGroup& GetSystemProperties() const { return mProperties.Get(); } + + private: + StringProperty mComponentType; + GroupProperty mProperties; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * User can send this message to cause the map system to spawn an entity from the given spawner. + * The contained unique id will be assigned to the spawned entity. + */ + class DT_ENTITY_EXPORT SpawnEntityMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId UniqueIdId; + static const StringId EntityNameId; + static const StringId SpawnerNameId; + static const StringId AddToSceneId; + SpawnEntityMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + void SetUniqueId(const std::string& v) { mUniqueId.Set(v); } + std::string GetUniqueId() const { return mUniqueId.Get(); } + + std::string GetSpawnerName() const { return mSpawnerName.Get(); } + void SetSpawnerName(const std::string& v) { mSpawnerName.Set(v); } + + std::string GetEntityName() const { return mEntityName.Get(); } + void SetEntityName(const std::string& v) { mEntityName.Set(v); } + + bool GetAddToScene() const { return mAddToScene.Get(); } + void SetAddToScene(bool v) { mAddToScene.Set(v); } + + private: + + StringProperty mUniqueId; + StringProperty mEntityName; + StringProperty mSpawnerName; + BoolProperty mAddToScene; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Send this to cause the tool system to switch to using the named tool + */ + class DT_ENTITY_EXPORT ToolActivatedMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId ToolNameId; + + ToolActivatedMessage(); + + // Create a copy of this message on the heap + virtual Message* Clone() const { return CloneContainer(); } + + void SetToolName(const std::string& n) { mToolName.Set(n); } + std::string GetToolName() const { return mToolName.Get(); } + + private: + + StringProperty mToolName; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** send this when you have added or removed a tool from tool manager + * mTools property should have data in this format: + * mtools contains a number of group properties. + * Each group property has entries + * StringProperty "ToolName" - name of tool as registered in tool manager + * StringProperty "IconPath" - path to icon to display for tool + * StringProperty "Shortcut" - keyboard shortcut for tool, example: "Ctrl+t" + */ + class DT_ENTITY_EXPORT ToolsUpdatedMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId ToolsId; + static const StringId ToolNameId; + static const StringId IconPathId; + static const StringId ShortcutId; + + ToolsUpdatedMessage(); + + // Create a copy of this message on the heap + virtual Message* Clone() const { return CloneContainer(); } + + void SetTools(const PropertyArray& n) { mTools.Set(n); } + PropertyArray GetTools() const { return mTools.Get(); } + + private: + + ArrayProperty mTools; + }; +} diff --git a/external/dtEntity/include/dtEntity/component.h b/external/dtEntity/include/dtEntity/component.h new file mode 100644 index 000000000..77963c3e9 --- /dev/null +++ b/external/dtEntity/include/dtEntity/component.h @@ -0,0 +1,60 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include + +namespace dtEntity +{ + class Entity; + + /** + * Components are lightweight property containers. + * Components can be used as per-entity data storage for entity systems. + * It is probably best to keep components as slim as possible and + * keep the logic in the entity systems. + */ + class Component + : public PropertyContainer + { + public: + + Component() {} + virtual ~Component() {} + + /** + * Return a unique identifier for this component + */ + virtual ComponentType GetType() const = 0; + + /** + * Gets called when component is instantiated + */ + virtual void OnAddedToEntity(Entity& entity) {} + + /** + * Gets called right before component is deleted + */ + virtual void OnRemovedFromEntity(Entity& entity) {} + + }; +} + diff --git a/external/dtEntity/include/dtEntity/componentfactories.h b/external/dtEntity/include/dtEntity/componentfactories.h new file mode 100644 index 000000000..5de5a3942 --- /dev/null +++ b/external/dtEntity/include/dtEntity/componentfactories.h @@ -0,0 +1,29 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include + +namespace dtEntity +{ + class ComponentPluginManager; + void DT_ENTITY_EXPORT RegisterStandardFactories(dtEntity::ComponentPluginManager& pluginManager); +} diff --git a/external/dtEntity/include/dtEntity/componentplugin.h b/external/dtEntity/include/dtEntity/componentplugin.h new file mode 100644 index 000000000..16dac0718 --- /dev/null +++ b/external/dtEntity/include/dtEntity/componentplugin.h @@ -0,0 +1,113 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include + +namespace dtEntity +{ + class EntityManager; + class EntitySystem; + + + /** + * PluginFactory is a pure virtual interface for the values + * returned by an entity system plugin entry point. + * The plugin factories are stored in the plugin manager and are used to list available + * entity systems, start and stop them. + */ + class ComponentPluginFactory + { + public: + + virtual ~ComponentPluginFactory() + { + } + + /** get the name of the entity system (the type string) */ + virtual std::string GetName() const = 0; + + /** + * Implementations should construct their entity system now and assign it to es variable + * Return true if success, else false + */ + virtual bool Create(EntityManager* em, EntitySystem*& es) = 0; + + /** delete the entity system */ + virtual void Destroy() {} + + /** + * return a textual description of the entity system functionality + */ + virtual std::string GetDescription() const { return ""; } + + /** + * fill list with types of all entity systems this system depends on. + * WARNING: circular dependencies are not handled and + * will cause a crash! + */ + virtual void GetDependencies(std::list&) {} + + osgDB::DynamicLibrary* GetLibrary() const { return mLibrary.get(); } + void SetLibrary(osgDB::DynamicLibrary* l) { mLibrary = l; } + + protected: + + osg::ref_ptr mLibrary; + }; + + template + class ComponentPluginFactoryImpl : public ComponentPluginFactory + { + public: + + ComponentPluginFactoryImpl(const std::string& name, const std::string& desc = "") + : mName(name) + , mDesc(desc) + { + } + + virtual bool Create(EntityManager* em, EntitySystem*& es) + { + es = new ES(*em); + return true; + } + + /** get the name of the plugin */ + virtual std::string GetName() const + { + return mName; + } + + /** get a description of the plugin */ + virtual std::string GetDescription() const + { + return mDesc; + } + private: + std::string mName; + std::string mDesc; + }; +} diff --git a/external/dtEntity/include/dtEntity/componentpluginmanager.h b/external/dtEntity/include/dtEntity/componentpluginmanager.h new file mode 100644 index 000000000..de1dab02f --- /dev/null +++ b/external/dtEntity/include/dtEntity/componentpluginmanager.h @@ -0,0 +1,169 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace dtEntity +{ + class MessageFactory; + + void DT_ENTITY_EXPORT AddToList(std::list& lst, int count, ...); + + // typedef for function pointer to get message factory from library + typedef void (*RegisterMessagesFn)(MessageFactory&); + + // typedef for function pointer to get entity system factory from library + typedef void (*CreatePluginFactoriesFn)(std::list&); + + /** + * The plugin manager is responsible for loading entity system factories from plugins, + * keep them around until they are needed, and start and stop the entity systems. + */ + class DT_ENTITY_EXPORT ComponentPluginManager + : public Singleton + { + + public: + + ComponentPluginManager(); + ~ComponentPluginManager(); + + typedef std::map PluginFactoryMap; + typedef std::set ActivePlugins; + + /** + * is there a factory for an entity system of this type? + */ + bool FactoryExists(ComponentType ctype); + + /** + * load all libraries in dir and add component factories to registry + */ + void LoadPluginsInDir(const std::string& path); + + /** + * If entity of this type is registered, start it and add it to entity manager. + * @param name Name of plugin to start + * @return true if success + */ + bool StartEntitySystem(EntityManager&, ComponentType ctype); + + /** + * stop all entity systems loaded from plugins and then unref the plugins + */ + void UnloadAllPlugins(EntityManager&); + + /** + * Directly add a factory for starting an entity system (instead of loading + * it from a plugin + */ + bool AddFactory(ComponentPluginFactory* factory); + + /** + * Load a shared library / dll from abs path and register + * the contained entity system factories + * A library can also be stored in the scene file, if desired (this can make it easier + * for applications to know what specific plugins to load). + * @abspath File name with path of plugin to load + * @saveWithScene Flag to tell if library will be saved with the scene (false by default) + * + * @return The list of new component types loaded from the plugin + */ + std::set AddPlugin(const std::string& abspath, bool saveWithScene = false); + + /** + * same as before, but doesn't expect a full path to plugin, instead takes + * a plugin directory and a library name without extension. + */ + std::set AddPlugin(const std::string& path, const std::string& libname, bool saveWithScene = false); + + /// Retrieves the names of the currently loaded plugins (with no path and no extension) + const std::map& GetLoadedPlugins() const { return mLoadedPlugins; } + + PluginFactoryMap& GetFactories() { return mFactories; } + + // get extension appended to lib name to point to shared library name + static std::string GetLibExtension(); + + // get library file name from plugin name, platform dependent + std::string GetSharedLibNameFromPluginName(const std::string& pluginName); + + private: + + /** Get PluginFactory for Plugin with this name. + * @param name The name of the Plugin/PluginFactory to get + */ + ComponentPluginFactory* GetPluginFactory(ComponentType ctype); + + /** load all plugin factories from libraries found in path */ + void LoadPluginFactories(const std::string& pluginname, const std::string& path, std::list& factories); + + /** map from plugin name -> plugin factory */ + PluginFactoryMap mFactories; + + /// List of libraries (plugins) currently loaded + /** + * We assume the library name is the same as the file name, with + * no path nor extension. We therefore just store the library name + * + The map stores each name with a flag that indicates if the library must be saved to + scene. It is up to the code filling this list to decide what libs must go to file. + */ + std::map mLoadedPlugins; + }; + +#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) + #define DTE_EXPORT_MACRO __declspec(dllexport) +#else + #define DTE_EXPORT_MACRO +#endif + +#define REGISTER_DTENTITYPLUGIN(pluginname, count, ...) \ + extern "C" DTE_EXPORT_MACRO void dtEntity_##pluginname(std::list& list) \ + {dtEntity::AddToList(list, count, __VA_ARGS__);} \ + + struct DT_ENTITY_EXPORT PluginFunctionProxy + { + PluginFunctionProxy(CreatePluginFactoriesFn plgfunction, RegisterMessagesFn msgfunction) ; + }; +} + +#if DTENTITY_LIBRARY_STATIC + + #define USE_DTENTITYPLUGIN(pluginname) \ + extern "C" void dtEntity_##pluginname(std::list&); \ + extern "C" void dtEntityMessages_##pluginname(dtEntity::MessageFactory& mf); \ + static dtEntity::PluginFunctionProxy proxy_##pluginname(dtEntity_##pluginname, dtEntityMessages_##pluginname); + +#else + #define USE_DTENTITYPLUGIN(pluginname) +#endif + + diff --git a/external/dtEntity/include/dtEntity/core.h b/external/dtEntity/include/dtEntity/core.h new file mode 100644 index 000000000..7677b3b23 --- /dev/null +++ b/external/dtEntity/include/dtEntity/core.h @@ -0,0 +1,44 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include + +namespace dtEntity +{ + + class DebugDrawInterface; + DT_ENTITY_EXPORT void SetDebugDrawInterface(DebugDrawInterface*); + DT_ENTITY_EXPORT DebugDrawInterface* GetDebugDrawInterface(); + + class InputInterface; + DT_ENTITY_EXPORT void SetInputInterface(InputInterface*); + DT_ENTITY_EXPORT InputInterface* GetInputInterface(); + + class SystemInterface; + DT_ENTITY_EXPORT void SetSystemInterface(SystemInterface*); + DT_ENTITY_EXPORT SystemInterface* GetSystemInterface(); + + class WindowInterface; + DT_ENTITY_EXPORT void SetWindowInterface(WindowInterface*); + DT_ENTITY_EXPORT WindowInterface* GetWindowInterface(); + +} diff --git a/external/dtEntity/include/dtEntity/debugdrawinterface.h b/external/dtEntity/include/dtEntity/debugdrawinterface.h new file mode 100644 index 000000000..52e516fe1 --- /dev/null +++ b/external/dtEntity/include/dtEntity/debugdrawinterface.h @@ -0,0 +1,211 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include + + +namespace dtEntity +{ + + /** + * Can be used to add simple debug geometry to the scene. Each debug graphics primitive is added + * together with a lifetime / duration. + * If you want to do per-frame drawing, simply set a duration of 0 and + * execute the draw each frame. + * Warning: To use, first do SetEnabled(true), it is off by default! + */ + class DebugDrawInterface + { + public: + + virtual ~DebugDrawInterface() {} + + /** + * Draw a single point + * @param position Draw point here + * @param color Draw with this color + * @param size Size of points in pixels + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + virtual void AddPoint(const Vec3f& position, const Vec4f& color, int size = 1, + float duration = 0, bool depthTestEnabled = true) = 0; + + /** + * Draw multiple points + * @param positions A vector of point positions + * @param color Draw with this color + * @param size Size of points in pixels + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + virtual void AddPoints(const std::vector& positions, const Vec4f& color, + int size = 1, float duration = 0, bool depthTestEnabled = true) = 0; + + /** + * Draw a single line + * @param start Line starts here + * @param end Line ends here + * @param color Draw with this color + * @param linewidth Width of line in pixels + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + virtual void AddLine(const Vec3f& start, const Vec3f& end, const Vec4f& color, + int linewidth = 1, float duration = 0, bool depthTestEnabled = true) = 0; + + /** + * Draw a number of lines + * @param lines A vector containing two entries for each line. So to draw two lines you have to have four entries. + * @param color Draw with this color + * @param linewidth Width of line in pixels + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + virtual void AddLines(const std::vector& lines, const Vec4f& color, + int linewidth = 1, float duration = 0, bool depthTestEnabled = true) = 0; + + /** + * Draw a 3d cross + * @param position Draw point here + * @param color Draw with this color + * @param size length of each arm + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + virtual void AddCross(const Vec3f& position, const Vec4f& color, float size, + float duration = 0, bool depthTestEnabled = true) = 0; + + /** + * Draw a sphere + * @param position Draw sphere here + * @param radius radius of sphere + * @param color Draw with this color + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + virtual void AddSphere(const Vec3f& position, float radius, const Vec4f& color, + float duration = 0, bool depthTestEnabled = true) = 0; + + /** + * Draw a single triangle + * @param vert0 First vertex of triangle + * @param vert1 Second vertex of triangle + * @param vert2 Third vertex of triangle + * @param color Draw with this color + * @param lineWidth with of line to draw in pixels + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + virtual void AddTriangle(const Vec3f& vert0, const Vec3f& vert1, + const Vec3f& vert2, const Vec4f& color, int lineWidth, + float duration = 0, bool depthTestEnabled = true) = 0; + + /** + * Draw multiple triangles + * @param verts A vector containing triangle verts. The vector should contain three entries for each triangle. + * @param color Draw with this color + * @param lineWidth with of line to draw in pixels + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + virtual void AddTriangles(const std::vector& verts, + const Vec4f& color, int lineWidth, float duration = 0, + bool depthTestEnabled = true) = 0; + + /** + * Draw a circle + * @param position Center of circle is here + * @param planeNormal A normal vector pointing away from the face of the disk + * @param radius Radius of disk + * @param color Draw with this color + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + virtual void AddCircle(const Vec3f& position, const Vec3f& planeNormal, + float radius, const Vec4f& color, float duration = 0, + bool depthTestEnabled = true) = 0; + + /** + * Draw a text string + * @param position Draw text here + * @param str The text to draw + * @param color Draw with this color + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + virtual void AddString(const Vec3f& position, const std::string& str, + const Vec4f& color, float duration = 0, bool depthTestEnabled = true) = 0; + + /** + * Draw an axis aligned bounding box + * @param minCoords start box from here + * @param maxCoords end box here + * @param color Draw with this color + * @param lineWidth with of line to draw + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + virtual void AddAABB(const Vec3f& minCoords, const Vec3f& maxCoords, + const Vec4f& color, int lineWidth, float duration = 0, + bool depthTestEnabled = true) = 0; + + /** + * Add an oriented bounding box + * @param matrix transformation matrix to apply to box + * @param minCoords start box from here + * @param maxCoords end box here + * @param color Draw with this color + * @param lineWidth with of line to draw + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + virtual void AddOBB(const Matrix& matrix, const Vec3f& minCoords, + const Vec3f& maxCoords, const Vec4f& color, int lineWidth, + float duration = 0, bool depthTestEnabled = true) = 0; + + /** + * Add a cross showing coordinate orientation + * @param matrix transformation cross by this matrix + * @param color Draw with this color + * @param size length of cross arms + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + virtual void AddAxes(const Matrix& matrix, const Vec4f& color, + float size, float duration = 0, bool depthTestEnabled = true) = 0; + + + /** + * DebugDrawInterface is disabled by default, enable it! + */ + virtual void SetEnabled(bool enabled) = 0; + virtual bool IsEnabled() const = 0; + + /** + * Immediately remove all debug geometry + */ + virtual void Clear() = 0; + + }; +} + diff --git a/external/dtEntity/include/dtEntity/defaultentitysystem.h b/external/dtEntity/include/dtEntity/defaultentitysystem.h new file mode 100644 index 000000000..ea72ee850 --- /dev/null +++ b/external/dtEntity/include/dtEntity/defaultentitysystem.h @@ -0,0 +1,335 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + + +#include +#include +#include + +#include +#include +#include + +#if USE_BOOST_POOL +#include +#include +#endif + +#include + + +namespace dtEntity +{ + + //////////////////////////////////////////////////////////////////////////////// + template + class ComponentStoreMap + : public std::unordered_map + { + public: + typedef typename std::unordered_map::size_type size_type; + + }; + + //////////////////////////////////////////////////////////////////////////////// + template + struct MemAllocPolicyNew + { + static T* Create() + { + return new T; + } + + static void Destroy(T* t) + { + delete t; + } + + static void DestroyAll(ComponentStoreMap& components) + { + for(typename ComponentStoreMap::iterator i = components.begin(); i != components.end(); ++i) + { + delete i->second; + } + } + + protected: + ~MemAllocPolicyNew() {} + }; + + + //////////////////////////////////////////////////////////////////////////////// +#if USE_BOOST_POOL + template + struct MemAllocPolicyBoostPool + { + static T* Create() + { + return mComponentPool->construct(); + } + + static void Destroy(T* t) + { + mComponentPool->destroy(t); + } + + static void DestroyAll(ComponentStoreMap& components) + { + delete mComponentPool; + } + + protected: + ~MemAllocPolicyBoostPool() {} + + private: + boost::object_pool* mComponentPool; + }; +#endif + + //////////////////////////////////////////////////////////////////////////////// + /** + * A simple base for an entity system that handles component allocation + * and deletion. + * Uses an unordered map for component storage + */ + template class MemAllocPolicy = MemAllocPolicyNew> + class DefaultEntitySystem + : public EntitySystem + , public MemAllocPolicy + { + public: + + typedef ComponentStoreMap ComponentStore; + typedef typename ComponentStoreMap::size_type size_type; + + DefaultEntitySystem(EntityManager& em, ComponentType baseType = StringId()) + : EntitySystem(em, baseType) + , mComponentType(T::TYPE) + { + } + + ~DefaultEntitySystem() + { + MemAllocPolicy::DestroyAll(mComponents); + } + + virtual ComponentType GetComponentType() const; + + virtual bool HasComponent(EntityId eid) const; + + T* GetComponent(EntityId eid); + const T* GetComponent(EntityId eid) const; + + virtual bool GetComponent(EntityId eid, Component*& c); + virtual bool GetComponent(EntityId eid, const Component*& c) const; + + virtual bool CreateComponent(EntityId eid, Component*& component); + virtual bool DeleteComponent(EntityId eid); + + virtual void GetEntitiesInSystem(std::list& toFill) const; + + size_type GetNumComponents() const; + + virtual GroupProperty GetComponentProperties() const; + + typename ComponentStore::iterator begin(); + typename ComponentStore::const_iterator begin() const; + + typename ComponentStore::iterator end(); + typename ComponentStore::const_iterator end() const; + + protected: + + ComponentStore mComponents; + ComponentType mComponentType; + }; + + + + //////////////////////////////////////////////////////////////////////////////// + template class MemAllocPolicy> + ComponentType DefaultEntitySystem::GetComponentType() const + { + return mComponentType; + } + + //////////////////////////////////////////////////////////////////////////////// + template class MemAllocPolicy> + bool DefaultEntitySystem::HasComponent(EntityId eid) const + { + typename ComponentStore::const_iterator i = mComponents.find(eid); + return(i != mComponents.end()); + } + + //////////////////////////////////////////////////////////////////////////////// + template class MemAllocPolicy> + T* DefaultEntitySystem::GetComponent(EntityId eid) + { + typename ComponentStore::iterator i = mComponents.find(eid); + if(i != mComponents.end()) + { + return i->second; + } + return NULL; + } + + //////////////////////////////////////////////////////////////////////////////// + template class MemAllocPolicy> + const T* DefaultEntitySystem::GetComponent(EntityId eid) const + { + typename ComponentStore::const_iterator i = mComponents.find(eid); + if(i != mComponents.end()) + { + return i->second; + } + return NULL; + } + + //////////////////////////////////////////////////////////////////////////////// + template class MemAllocPolicy> + bool DefaultEntitySystem::GetComponent(EntityId eid, Component*& c) + { + typename ComponentStore::iterator i = mComponents.find(eid); + if(i != mComponents.end()) + { + c = i->second; + return true; + } + return false; + } + + //////////////////////////////////////////////////////////////////////////////// + template class MemAllocPolicy> + bool DefaultEntitySystem::GetComponent(EntityId eid, const Component*& c) const + { + typename ComponentStore::const_iterator i = mComponents.find(eid); + if(i != mComponents.end()) + { + c = i->second; + return true; + } + return false; + } + + //////////////////////////////////////////////////////////////////////////////// + template class MemAllocPolicy> + bool DefaultEntitySystem::CreateComponent(EntityId eid, Component*& component) + { + if(HasComponent(eid)) + { + LOG_ERROR("Could not create component: already exists!"); + return false; + } + + T* t = MemAllocPolicy::Create(); + + if(t == NULL) + { + LOG_ERROR("Out of memory!"); + return false; + } + component = t; + mComponents[eid] = t; + + Entity* e; + bool found = GetEntityManager().GetEntity(eid, e); + if(!found) + { + LOG_ERROR("Can't add component to entity: entity does not exist!"); + return false; + } + component->OnAddedToEntity(*e); + return true; + } + + //////////////////////////////////////////////////////////////////////////////// + template class MemAllocPolicy> + bool DefaultEntitySystem::DeleteComponent(EntityId eid) + { + typename ComponentStore::iterator i = mComponents.find(eid); + if(i == mComponents.end()) + return false; + T* component = i->second; + Entity* e; + bool found = GetEntityManager().GetEntity(eid, e); + assert(found); + component->OnRemovedFromEntity(*e); + mComponents.erase(i); + MemAllocPolicy::Destroy(component); + return true; + } + + //////////////////////////////////////////////////////////////////////////////// + template class MemAllocPolicy> + void DefaultEntitySystem::GetEntitiesInSystem(std::list& toFill) const + { + typename ComponentStore::const_iterator i = mComponents.begin(); + for(;i != mComponents.end(); ++i) + { + toFill.push_back(i->first); + } + } + + //////////////////////////////////////////////////////////////////////////////// + template class MemAllocPolicy> + typename DefaultEntitySystem::size_type DefaultEntitySystem::GetNumComponents() const + { + return mComponents.size(); + } + + //////////////////////////////////////////////////////////////////////////////// + template class MemAllocPolicy> + GroupProperty DefaultEntitySystem::GetComponentProperties() const + { + T t; + return t; + } + + //////////////////////////////////////////////////////////////////////////////// + template class MemAllocPolicy> + typename ComponentStoreMap::iterator DefaultEntitySystem::begin() + { + return mComponents.begin(); + } + + //////////////////////////////////////////////////////////////////////////////// + template class MemAllocPolicy> + typename ComponentStoreMap::const_iterator DefaultEntitySystem::begin() const + { + return mComponents.begin(); + } + + //////////////////////////////////////////////////////////////////////////////// + template class MemAllocPolicy> + typename ComponentStoreMap::iterator DefaultEntitySystem::end() + { + return mComponents.end(); + } + + //////////////////////////////////////////////////////////////////////////////// + template class MemAllocPolicy> + typename ComponentStoreMap::const_iterator DefaultEntitySystem::end() const + { + return mComponents.end(); + } +} + diff --git a/external/dtEntity/include/dtEntity/dtentity_config.h b/external/dtEntity/include/dtEntity/dtentity_config.h new file mode 100644 index 000000000..92aa5c8af --- /dev/null +++ b/external/dtEntity/include/dtEntity/dtentity_config.h @@ -0,0 +1,32 @@ +#pragma once + +// auto-generated by CMake, do not edit! + +#define DTENTITY_VERSION_MAJOR 0 +#define DTENTITY_VERSION_MINOR 1 +#define DTENTITY_VERSION_PATCH 1 + +// build entity systems for sound support? +#define BUILD_OPENAL 0 + +// should boost::pool be used for memory allocations of components? +#define USE_BOOST_POOL 0 + +// build dtEntity and its libs as static libraries? +#define DTENTITY_LIBRARY_STATIC 0 + +// use strings instead of hash values? +#define DTENTITY_USE_STRINGS_AS_STRINGIDS 0 + +// was google protocol buffers found by cmake? +#define PROTOBUF_FOUND 0 + +// was enet found by cmake? +#define ENET_FOUND 0 + +// should dtEntity call OnPropertyChanged() method when a property of a component +// was changed? For backwards compability only +#define CALL_ONPROPERTYCHANGED_METHOD 1 + +// Should message calls be profiled? +#define DTENTITY_PROFILING_ENABLED 0 diff --git a/external/dtEntity/include/dtEntity/dynamicproperty.h b/external/dtEntity/include/dtEntity/dynamicproperty.h new file mode 100644 index 000000000..16d422343 --- /dev/null +++ b/external/dtEntity/include/dtEntity/dynamicproperty.h @@ -0,0 +1,628 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include + +namespace dtEntity +{ + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT DynamicArrayProperty : public Property + { + public: + typedef fastdelegate::FastDelegate1 SetValueCB; + typedef fastdelegate::FastDelegate0 GetValueCB; + + DynamicArrayProperty() {} + + DynamicArrayProperty(const SetValueCB& s, const GetValueCB& g) + : mSetValueCallback(s) + , mGetValueCallback(g) + { + } + + virtual DataType::e GetDataType() const { return DataType::ARRAY; } + + virtual PropertyArray ArrayValue() const { return mGetValueCallback(); } + virtual void SetArray(const PropertyArray& v) { Set(v); } + + virtual const std::string StringValue() const { ArrayProperty p(Get()); return p.StringValue(); } + virtual void SetString(const std::string& v) { ArrayProperty p; p.SetString(v); Set(p.Get());} + PropertyArray Get() const { return mGetValueCallback(); } + + virtual Property* Clone() const { return new ArrayProperty(Get()); } + virtual bool operator==(const Property& other) const { return other.ArrayValue() == Get(); } + void Set(const PropertyArray& v) { mSetValueCallback(v); } + virtual bool SetFrom(const Property& other) { Set(other.ArrayValue()); return true; } + + private: + + SetValueCB mSetValueCallback; + GetValueCB mGetValueCallback; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT DynamicBoolProperty : public Property + { + public: + typedef fastdelegate::FastDelegate1 SetValueCB; + typedef fastdelegate::FastDelegate0 GetValueCB; + + DynamicBoolProperty() {} + + DynamicBoolProperty(const SetValueCB& s, const GetValueCB& g) + : mSetValueCallback(s) + , mGetValueCallback(g) + { + } + + virtual DataType::e GetDataType() const { return DataType::BOOL; } + + virtual bool BoolValue() const { return mGetValueCallback(); } + virtual void SetBool(bool v) { Set(v); } + + virtual const std::string StringValue() const { BoolProperty p(Get()); return p.StringValue(); } + virtual void SetString(const std::string& v) { BoolProperty p; p.SetString(v); Set(p.Get());} + bool Get() const { return mGetValueCallback(); } + + virtual Property* Clone() const { return new BoolProperty(Get()); } + virtual bool operator==(const Property& other) const { return other.BoolValue() == Get(); } + void Set(bool v) { mSetValueCallback(v); } + virtual bool SetFrom(const Property& other) { Set(other.BoolValue()); return true; } + + private: + + SetValueCB mSetValueCallback; + GetValueCB mGetValueCallback; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT DynamicDoubleProperty : public Property + { + public: + typedef fastdelegate::FastDelegate1 SetValueCB; + typedef fastdelegate::FastDelegate0 GetValueCB; + + DynamicDoubleProperty() {} + + DynamicDoubleProperty(const SetValueCB& s, const GetValueCB& g) + : mSetValueCallback(s) + , mGetValueCallback(g) + { + } + + virtual DataType::e GetDataType() const { return DataType::DOUBLE; } + + virtual double DoubleValue() const { return mGetValueCallback(); } + virtual void SetDouble(double v) { Set(v); } + + virtual const std::string StringValue() const { DoubleProperty p(Get()); return p.StringValue(); } + virtual void SetString(const std::string& v) { DoubleProperty p; p.SetString(v); Set(p.Get());} + double Get() const { return mGetValueCallback(); } + + virtual Property* Clone() const { return new DoubleProperty(Get()); } + virtual bool operator==(const Property& other) const { return other.DoubleValue() == Get(); } + void Set(double v) { mSetValueCallback(v); } + virtual bool SetFrom(const Property& other) { Set(other.DoubleValue()); return true; } + + private: + + SetValueCB mSetValueCallback; + GetValueCB mGetValueCallback; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT DynamicFloatProperty : public Property + { + public: + typedef fastdelegate::FastDelegate1 SetValueCB; + typedef fastdelegate::FastDelegate0 GetValueCB; + + DynamicFloatProperty() {} + + DynamicFloatProperty(const SetValueCB& s, const GetValueCB& g) + : mSetValueCallback(s) + , mGetValueCallback(g) + { + } + + virtual DataType::e GetDataType() const { return DataType::FLOAT; } + + virtual float FloatValue() const { return mGetValueCallback(); } + virtual void SetFloat(float v) { Set(v); } + + virtual const std::string StringValue() const { FloatProperty p(Get()); return p.StringValue(); } + virtual void SetString(const std::string& v) { FloatProperty p; p.SetString(v); Set(p.Get());} + float Get() const { return mGetValueCallback(); } + + virtual Property* Clone() const { return new FloatProperty(Get()); } + virtual bool operator==(const Property& other) const { return other.FloatValue() == Get(); } + void Set(float v) { mSetValueCallback(v); } + virtual bool SetFrom(const Property& other) { Set(other.FloatValue()); return true; } + + private: + + SetValueCB mSetValueCallback; + GetValueCB mGetValueCallback; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT DynamicGroupProperty : public Property + { + public: + typedef fastdelegate::FastDelegate1 SetValueCB; + typedef fastdelegate::FastDelegate0 GetValueCB; + + DynamicGroupProperty() {} + + DynamicGroupProperty(const SetValueCB& s, const GetValueCB& g) + : mSetValueCallback(s) + , mGetValueCallback(g) + { + } + + virtual DataType::e GetDataType() const { return DataType::GROUP; } + + virtual PropertyGroup GroupValue() const { return mGetValueCallback(); } + virtual void SetGroup(const PropertyGroup& v) { Set(v); } + + virtual const std::string StringValue() const { GroupProperty p(Get()); return p.StringValue(); } + virtual void SetString(const std::string& v) { GroupProperty p; p.SetString(v); Set(p.Get());} + PropertyGroup Get() const { return mGetValueCallback(); } + + virtual Property* Clone() const { return new GroupProperty(Get()); } + virtual bool operator==(const Property& other) const { return other.GroupValue() == Get(); } + void Set(const PropertyGroup& v) { mSetValueCallback(v); } + virtual bool SetFrom(const Property& other) { Set(other.GroupValue()); return true; } + + private: + + SetValueCB mSetValueCallback; + GetValueCB mGetValueCallback; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT DynamicIntProperty : public Property + { + public: + typedef fastdelegate::FastDelegate1 SetValueCB; + typedef fastdelegate::FastDelegate0 GetValueCB; + + DynamicIntProperty() {} + + DynamicIntProperty(const SetValueCB& s, const GetValueCB& g) + : mSetValueCallback(s) + , mGetValueCallback(g) + { + } + + virtual DataType::e GetDataType() const { return DataType::INT; } + + virtual int IntValue() const { return mGetValueCallback(); } + virtual void SetInt(int v) { Set(v); } + + virtual const std::string StringValue() const { IntProperty p(Get()); return p.StringValue(); } + virtual void SetString(const std::string& v) { IntProperty p; p.SetString(v); Set(p.Get());} + int Get() const { return mGetValueCallback(); } + + virtual Property* Clone() const { return new IntProperty(Get()); } + virtual bool operator==(const Property& other) const { return other.IntValue() == Get(); } + void Set(int v) { mSetValueCallback(v); } + virtual bool SetFrom(const Property& other) { Set(other.IntValue()); return true; } + + private: + + SetValueCB mSetValueCallback; + GetValueCB mGetValueCallback; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT DynamicStringProperty : public Property + { + public: + typedef fastdelegate::FastDelegate1< const std::string&, void> SetValueCB; + typedef fastdelegate::FastDelegate0 GetValueCB; + + DynamicStringProperty() {} + + DynamicStringProperty(const SetValueCB& s, const GetValueCB& g) + : mSetValueCallback(s) + , mGetValueCallback(g) + { + } + + virtual DataType::e GetDataType() const { return DataType::STRING; } + + virtual const std::string StringValue() const { return mGetValueCallback(); } + virtual StringId StringIdValue() const { return dtEntity::SIDHash(StringValue()); } + //virtual void SetStringId(dtEntity::StringId v) { Set(GetStringFromSID(v)); } + + const std::string Get() const { return mGetValueCallback(); } + + virtual Property* Clone() const { return new StringProperty(Get()); } + virtual bool operator==(const Property& other) const { return other.StringValue() == Get(); } + void Set(const std::string& v) { mSetValueCallback(v); } + virtual void SetString(const std::string& v) { Set(v); } + virtual bool SetFrom(const Property& other) { Set(other.StringValue()); return true; } + + private: + + SetValueCB mSetValueCallback; + GetValueCB mGetValueCallback; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT DynamicStringIdProperty : public Property + { + public: + typedef fastdelegate::FastDelegate1 SetValueCB; + typedef fastdelegate::FastDelegate0 GetValueCB; + + DynamicStringIdProperty() {} + + DynamicStringIdProperty(const SetValueCB& s, const GetValueCB& g) + : mSetValueCallback(s) + , mGetValueCallback(g) + { + } + + virtual DataType::e GetDataType() const { return DataType::STRINGID; } + + virtual StringId StringIdValue() const { return mGetValueCallback(); } + virtual void SetStringId(StringId v) { Set(v); } + + virtual const std::string StringValue() const { StringIdProperty p(Get()); return p.StringValue(); } + virtual void SetString(const std::string& v) { StringIdProperty p; p.SetString(v); Set(p.Get());} + StringId Get() const { return mGetValueCallback(); } + + virtual Property* Clone() const { return new StringIdProperty(Get()); } + virtual bool operator==(const Property& other) const { return other.StringIdValue() == Get(); } + void Set(StringId v) { mSetValueCallback(v); } + virtual bool SetFrom(const Property& other) { Set(other.StringIdValue()); return true; } + + private: + + SetValueCB mSetValueCallback; + GetValueCB mGetValueCallback; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT DynamicUIntProperty : public Property + { + public: + typedef fastdelegate::FastDelegate1 SetValueCB; + typedef fastdelegate::FastDelegate0 GetValueCB; + + DynamicUIntProperty() {} + + DynamicUIntProperty(const SetValueCB& s, const GetValueCB& g) + : mSetValueCallback(s) + , mGetValueCallback(g) + { + } + + virtual DataType::e GetDataType() const { return DataType::UINT; } + + virtual unsigned int UIntValue() const { return mGetValueCallback(); } + virtual void SetUInt(unsigned int v) { Set(v); } + + virtual const std::string StringValue() const { UIntProperty p(Get()); return p.StringValue(); } + virtual void SetString(const std::string& v) { UIntProperty p; p.SetString(v); Set(p.Get());} + unsigned int Get() const { return mGetValueCallback(); } + + virtual Property* Clone() const { return new UIntProperty(Get()); } + virtual bool operator==(const Property& other) const { return other.UIntValue() == Get(); } + void Set(unsigned int v) { mSetValueCallback(v); } + virtual bool SetFrom(const Property& other) { Set(other.UIntValue()); return true; } + + private: + + SetValueCB mSetValueCallback; + GetValueCB mGetValueCallback; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT DynamicVec2dProperty : public Property + { + public: + typedef fastdelegate::FastDelegate1< const Vec2d&, void> SetValueCB; + typedef fastdelegate::FastDelegate0 GetValueCB; + + DynamicVec2dProperty() {} + + DynamicVec2dProperty(const SetValueCB& s, const GetValueCB& g) + : mSetValueCallback(s) + , mGetValueCallback(g) + { + } + + virtual DataType::e GetDataType() const { return DataType::VEC2D; } + + virtual Vec2f Vec2Value() const { return Get(); } + virtual void SetVec2(const Vec2f& v) { Set(v); } + virtual Vec2d Vec2dValue() const { return Get(); } + virtual void SetVec2D(const Vec2d& v) { Set(v); } + virtual const std::string StringValue() const { Vec2dProperty p(Get()); return p.StringValue(); } + Vec2d Get() const { return mGetValueCallback(); } + + virtual Property* Clone() const { return new Vec2dProperty(Get()); } + virtual bool operator==(const Property& other) const { return other.Vec2dValue() == Get(); } + void Set(const Vec2d& v) { mSetValueCallback(v); } + virtual void SetString(const std::string& v) { Vec2dProperty p; p.SetString(v); Set(p.Get());} + virtual bool SetFrom(const Property& other) { Set(other.Vec2dValue()); return true; } + + private: + + SetValueCB mSetValueCallback; + GetValueCB mGetValueCallback; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT DynamicVec3dProperty : public Property + { + public: + typedef fastdelegate::FastDelegate1< const Vec3d&, void> SetValueCB; + typedef fastdelegate::FastDelegate0 GetValueCB; + + DynamicVec3dProperty() {} + + DynamicVec3dProperty(const SetValueCB& s, const GetValueCB& g) + : mSetValueCallback(s) + , mGetValueCallback(g) + { + } + + virtual DataType::e GetDataType() const { return DataType::VEC3D; } + + virtual Vec3f Vec3Value() const { return Get(); } + virtual void SetVec3(const Vec3f& v) { Set(v); } + virtual Vec3d Vec3dValue() const { return Get(); } + virtual void SetVec3D(const Vec3d& v) { Set(v); } + virtual const std::string StringValue() const { Vec3dProperty p(Get()); return p.StringValue(); } + Vec3d Get() const { return mGetValueCallback(); } + + virtual Property* Clone() const { return new Vec3dProperty(Get()); } + virtual bool operator==(const Property& other) const { return other.Vec3dValue() == Get(); } + void Set(const Vec3d& v) { mSetValueCallback(v); } + virtual void SetString(const std::string& v) { Vec3dProperty p; p.SetString(v); Set(p.Get());} + virtual bool SetFrom(const Property& other) { Set(other.Vec3dValue()); return true; } + + private: + + SetValueCB mSetValueCallback; + GetValueCB mGetValueCallback; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT DynamicVec4dProperty : public Property + { + public: + typedef fastdelegate::FastDelegate1< const Vec4d&, void> SetValueCB; + typedef fastdelegate::FastDelegate0 GetValueCB; + + DynamicVec4dProperty() {} + + DynamicVec4dProperty(const SetValueCB& s, const GetValueCB& g) + : mSetValueCallback(s) + , mGetValueCallback(g) + { + } + + virtual DataType::e GetDataType() const { return DataType::VEC4D; } + + virtual Vec4f Vec4Value() const { return Get(); } + virtual void SetVec4(const Vec4f& v) { Set(v); } + virtual Vec4d Vec4dValue() const { return Get(); } + virtual void SetVec4D(const Vec4d& v) { Set(v); } + virtual const std::string StringValue() const { Vec4dProperty p(Get()); return p.StringValue(); } + Vec4d Get() const { return mGetValueCallback(); } + + virtual Property* Clone() const { return new Vec4dProperty(Get()); } + virtual bool operator==(const Property& other) const { return other.Vec4dValue() == Get(); } + void Set(const Vec4d& v) { mSetValueCallback(v); } + virtual void SetString(const std::string& v) { Vec4dProperty p; p.SetString(v); Set(p.Get());} + virtual bool SetFrom(const Property& other) { Set(other.Vec4dValue()); return true; } + + private: + + SetValueCB mSetValueCallback; + GetValueCB mGetValueCallback; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT DynamicVec2Property : public Property + { + public: + typedef fastdelegate::FastDelegate1 SetValueCB; + typedef fastdelegate::FastDelegate0 GetValueCB; + + DynamicVec2Property() {} + + DynamicVec2Property(const SetValueCB& s, const GetValueCB& g) + : mSetValueCallback(s) + , mGetValueCallback(g) + { + } + + virtual DataType::e GetDataType() const { return DataType::VEC2; } + + virtual Vec2f Vec2Value() const { return Get(); } + virtual void SetVec2(const Vec2f& v) { Set(v); } + virtual Vec2d Vec2dValue() const { return Get(); } + virtual void SetVec2D(const Vec2d& v) { Set(v); } + virtual const std::string StringValue() const { Vec2Property p(Get()); return p.StringValue(); } + Vec2f Get() const { return mGetValueCallback(); } + + virtual Property* Clone() const { return new Vec2Property(Get()); } + virtual bool operator==(const Property& other) const { return other.Vec2Value() == Get(); } + void Set(const Vec2f& v) { mSetValueCallback(v); } + virtual void SetString(const std::string& v) { Vec2Property p; p.SetString(v); Set(p.Get());} + virtual bool SetFrom(const Property& other) { Set(other.Vec2Value()); return true; } + + private: + + SetValueCB mSetValueCallback; + GetValueCB mGetValueCallback; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT DynamicVec3Property : public Property + { + public: + typedef fastdelegate::FastDelegate1< const Vec3f&, void> SetValueCB; + typedef fastdelegate::FastDelegate0 GetValueCB; + + DynamicVec3Property() {} + + DynamicVec3Property(const SetValueCB& s, const GetValueCB& g) + : mSetValueCallback(s) + , mGetValueCallback(g) + { + } + + virtual DataType::e GetDataType() const { return DataType::VEC3; } + + virtual Vec3f Vec3Value() const { return Get(); } + virtual void SetVec3(const Vec3f& v) { Set(v); } + virtual Vec3d Vec3dValue() const { return Get(); } + virtual void SetVec3D(const Vec3d& v) { Set(v); } + virtual const std::string StringValue() const { Vec3Property p(Get()); return p.StringValue(); } + Vec3f Get() const { return mGetValueCallback(); } + + virtual Property* Clone() const { return new Vec3Property(Get()); } + virtual bool operator==(const Property& other) const { return other.Vec3Value() == Get(); } + void Set(const Vec3f& v) { mSetValueCallback(v); } + virtual void SetString(const std::string& v) { Vec3Property p; p.SetString(v); Set(p.Get());} + virtual bool SetFrom(const Property& other) { Set(other.Vec3Value()); return true; } + + private: + + SetValueCB mSetValueCallback; + GetValueCB mGetValueCallback; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT DynamicVec4Property : public Property + { + public: + typedef fastdelegate::FastDelegate1< const Vec4f&, void> SetValueCB; + typedef fastdelegate::FastDelegate0 GetValueCB; + + DynamicVec4Property() {} + + DynamicVec4Property(const SetValueCB& s, const GetValueCB& g) + : mSetValueCallback(s) + , mGetValueCallback(g) + { + } + + virtual DataType::e GetDataType() const { return DataType::VEC4; } + + virtual Vec4f Vec4Value() const { return Get(); } + virtual void SetVec4(const Vec4f& v) { Set(v); } + virtual Vec4d Vec4dValue() const { return Get(); } + virtual void SetVec4D(const Vec4d& v) { Set(v); } + virtual const std::string StringValue() const { Vec4Property p(Get()); return p.StringValue(); } + Vec4f Get() const { return mGetValueCallback(); } + + virtual Property* Clone() const { return new Vec4Property(Get()); } + virtual bool operator==(const Property& other) const { return other.Vec4Value() == Get(); } + void Set(const Vec4f& v) { mSetValueCallback(v); } + virtual void SetString(const std::string& v) { Vec4Property p; p.SetString(v); Set(p.Get());} + virtual bool SetFrom(const Property& other) { Set(other.Vec4Value()); return true; } + + private: + + SetValueCB mSetValueCallback; + GetValueCB mGetValueCallback; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT DynamicQuatProperty : public Property + { + public: + typedef fastdelegate::FastDelegate1< const Quat&, void> SetValueCB; + typedef fastdelegate::FastDelegate0 GetValueCB; + + virtual DataType::e GetDataType() const { return DataType::QUAT; } + + DynamicQuatProperty() {} + + DynamicQuatProperty(const SetValueCB& s, const GetValueCB& g) + : mSetValueCallback(s) + , mGetValueCallback(g) + { + } + + virtual Quat QuatValue() const { return Get(); } + virtual void SetQuat(const Quat& v) { Set(v); } + virtual const std::string StringValue() const { QuatProperty p(Get()); return p.StringValue(); } + Quat Get() const { return mGetValueCallback(); } + + virtual Property* Clone() const { return new QuatProperty(Get()); } + virtual bool operator==(const Property& other) const { return other.QuatValue() == Get(); } + void Set(const Quat& v) { mSetValueCallback(v); } + virtual void SetString(const std::string& v) { QuatProperty p; p.SetString(v); Set(p.Get());} + virtual bool SetFrom(const Property& other) { Set(other.QuatValue()); return true; } + + private: + + SetValueCB mSetValueCallback; + GetValueCB mGetValueCallback; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT DynamicMatrixProperty : public Property + { + public: + typedef fastdelegate::FastDelegate1 SetValueCB; + typedef fastdelegate::FastDelegate0 GetValueCB; + + virtual DataType::e GetDataType() const { return DataType::MATRIX; } + + DynamicMatrixProperty() {} + + DynamicMatrixProperty(const SetValueCB& s, const GetValueCB& g) + : mSetValueCallback(s) + , mGetValueCallback(g) + { + } + + virtual Matrix MatrixValue() const { return Get(); } + virtual void SetMatrix(const Matrix& v) { Set(v); } + virtual const std::string StringValue() const { MatrixProperty p(Get()); return p.StringValue(); } + Matrix Get() const { return mGetValueCallback(); } + + virtual Property* Clone() const { return new MatrixProperty(Get()); } + virtual bool operator==(const Property& other) const { return other.MatrixValue() == Get(); } + void Set(const Matrix& v) { mSetValueCallback(v); } + virtual void SetString(const std::string& v) { MatrixProperty p; p.SetString(v); Set(p.Get());} + virtual bool SetFrom(const Property& other) { Set(other.MatrixValue()); return true;} + + private: + + SetValueCB mSetValueCallback; + GetValueCB mGetValueCallback; + }; + +} diff --git a/external/dtEntity/include/dtEntity/dynamicscomponent.h b/external/dtEntity/include/dtEntity/dynamicscomponent.h new file mode 100644 index 000000000..2d978e8dd --- /dev/null +++ b/external/dtEntity/include/dtEntity/dynamicscomponent.h @@ -0,0 +1,88 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include + +namespace dtEntity +{ + + + /////////////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT DynamicsComponent + : public Component + { + public: + + typedef Component BaseClass; + + static const ComponentType TYPE; + static const StringId VelocityId; + static const StringId AngularVelocityId; + static const StringId AccelerationId; + + DynamicsComponent(); + virtual ~DynamicsComponent(); + + virtual ComponentType GetType() const { return TYPE; } + + void OnAddedToEntity(Entity &entity) { mEntity = &entity; } + + Vec3f GetVelocity() const { return mVelocityVal; } + void SetVelocity(const Vec3f& v); + + const Quat& GetAngularVelocity() const { return mAngularVelocity.GetAsQuat(); } + void SetAngularVelocity(const Quat& v) { mAngularVelocity.Set(v); } + + const Vec3f& GetAcceleration() const { return mAcceleration.GetAsVec3(); } + void SetAcceleration(const Vec3f& v) { mAcceleration.Set(v); } + + protected: + Entity* mEntity; + + // path to loaded script file + DynamicVec3Property mVelocity; + Vec3f mVelocityVal; + QuatProperty mAngularVelocity; + Vec3Property mAcceleration; + bool mIsMoving; + + }; + + + /////////////////////////////////////////////////////////////////////////// + // storage only + class DT_ENTITY_EXPORT DynamicsSystem + : public DefaultEntitySystem + { + public: + + static const ComponentType TYPE; + + DynamicsSystem(EntityManager& em); + ~DynamicsSystem(); + + }; +} diff --git a/external/dtEntity/include/dtEntity/entity.h b/external/dtEntity/include/dtEntity/entity.h new file mode 100644 index 000000000..873dbedf0 --- /dev/null +++ b/external/dtEntity/include/dtEntity/entity.h @@ -0,0 +1,129 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include + +namespace dtEntity +{ + + /** + * The entity class is simply a convenience class to bundle + * the entity ID and access to the entity manager. + */ + class DT_ENTITY_EXPORT Entity + { + public: + + /** + * Constructor. + * @param em The entity manager that holds this entity + * @param id The unique ID of this entity + */ + Entity(EntityManager& em, EntityId id); + + /** + * Create a component of given type and assign it to component + * @param t Type of component to construct + * @param component Receives newly constructed component + * @return true if success + */ + bool CreateComponent(ComponentType t, Component*& component); + + // templated version + template + bool CreateComponent(T*& component); + + /** + * Get component from this entity + * @param component receives the component if found + * @param searchDerived Return components of derived typs if found + * @return true if found + */ + template + bool GetComponent(T*& component, bool searchDerived = false) const; + + /** + * Get component from this entity + * @param component receives the component if found + * @param searchDerived Return components of derived typs if found + * @return true if found + */ + bool GetComponent(ComponentType t, Component*& component, bool searchDerived = false) const; + + /** + * Get a list of all component associated with this entity + * @param toFill receives the components + */ + void GetComponents(std::vector& toFill); + void GetComponents(std::vector& toFill) const; + + /** + * @return true if a component of this type is assigned to entity + */ + bool HasComponent(ComponentType t) const; + + /** + * get unique identifier of this entity + */ + EntityId GetId() const; + + /** + * @return the entity manager this entity is assigned to + */ + EntityManager& GetEntityManager() const; + + private: + + // internal ID + EntityId mId; + + // The entity manager that holds this entity + EntityManager* mEntityManager; + }; + + + //////////////////////////////////////////////////////////////////////////////// + + + template + bool Entity::CreateComponent(T*& component) + { + Component* c; + bool success = CreateComponent(T::TYPE, c); + if (success) + component = static_cast(c); + else + component = nullptr; + return success; + } + + template + bool Entity::GetComponent(T*& component, bool derived) const + { + return GetEntityManager().GetComponent(this->GetId(), component, derived); + } +} + diff --git a/external/dtEntity/include/dtEntity/entityid.h b/external/dtEntity/include/dtEntity/entityid.h new file mode 100644 index 000000000..e009c189e --- /dev/null +++ b/external/dtEntity/include/dtEntity/entityid.h @@ -0,0 +1,27 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +namespace dtEntity +{ + // serial ID for entities + typedef unsigned int EntityId; +} diff --git a/external/dtEntity/include/dtEntity/entitymanager.h b/external/dtEntity/include/dtEntity/entitymanager.h new file mode 100644 index 000000000..42a60ee20 --- /dev/null +++ b/external/dtEntity/include/dtEntity/entitymanager.h @@ -0,0 +1,421 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace dtEntity +{ + class Component; + class Entity; + class EntitySystem; + class Message; + + /** + * Entity manager is a container for entity systems. + * Each entity system holds entity components of a specific type. + * The entity manager gives access to the entity systems and can be used to + * create, retrieve and delete components. + * + * Also, Entity manager is a central point to send and register to messages. + * Messages can be sent (emitted) immediately to all registrants, or they can be + * posted to a message queue to be emitted at a later time. + */ + class DT_ENTITY_EXPORT EntityManager + { + + public: + + /** + * Constructor. + * @param startEntitySystems if true, start default entity + * systems like OSG components etc + */ + EntityManager(); + + // Destructor + ~EntityManager(); + + /** + * can be used to clean up wrappers for components or + * execute other actions + */ + class ComponentDeletedCallback + { + public: + virtual void ComponentDeleted(ComponentType t, EntityId id) = 0; + virtual ~ComponentDeletedCallback() {} + }; + + typedef std::vector ComponentDeletedCallbacks; + + + /** + * If user executes CreateComponent and no entity system with given component + * type is registered then all EntitySystemRequestCallbacks are executed + * until one returns true. Callback can be used to add entity systems lazily. + */ + class EntitySystemRequestCallback + { + public: + virtual bool CreateEntitySystem(EntityManager* em, ComponentType t) = 0; + + virtual ~EntitySystemRequestCallback() {} + }; + + typedef std::vector EntitySystemRequestCallbacks; + + /** + * Get entity object for entity ID. + * @param id Unique id of the entity to retrieve + * @param entity Will receive pointer to entity object + * @return true if entity with this id was found + * @threadsafe + */ + bool GetEntity(EntityId id, Entity*& entity); + + /** + * return true if entity with this ID exists + */ + bool EntityExists(EntityId id) const; + + /** + * Fill vector with entity ids of all existing entities + */ + void GetEntityIds(std::vector& toFill); + + /** + * delete entity object and tell all entity systems to delete their + * components for this entity + * @param id id of the entity to delete + * @return true if success + * @threadsafe + */ + bool KillEntity(EntityId id); + + /** + * Create a new entity with a new unique EntityId + * All entities are deleted when entity manager is deleted. + * This method is thread safe so that entities can be created from + * worker threads. Creation and deletion of entities are + * thread-safe, all other entity system/component methods are + * non-tread safe. + * @param entity Receives pointer to newly created entity + * @return true if success + * @threadsafe + */ + bool CreateEntity(Entity*& entity); + + /** + * Loops through all components of origin and creates them on target entity + * @param target ID of an existing entity with no components + * @param origin Clone components of this entity + * @return true if success + */ + bool CloneEntity(EntityId target, EntityId origin); + + /** + * @param id Check if an entity with this id exists + * @return true if such an entity exists + */ + bool HasEntity(EntityId id) const; + + /** + * returns true while at least one entity exists + */ + bool HasEntities() const; + + /** + * DEPRECATED! Use MapSystem::AddToScene + */ + bool AddToScene(EntityId eid); + + /** + * DEPRECATED! Use MapSystem::RemoveFromScene + */ + bool RemoveFromScene(EntityId eid); + + /** + * @param id Check if an entity system of this component type is active + * @return true if such a system exists + */ + bool HasEntitySystem(ComponentType id) const; + + /** + * @param s Add this entity system to the manager + */ + bool AddEntitySystem(EntitySystem& s); + + /** + * @param s Remove this entity system + * @return true if entity system was registered, else false + */ + bool RemoveEntitySystem(EntitySystem& s); + + /** + * Get entity system of given type. + * Returns NULL if not found. + */ + EntitySystem* GetEntitySystem(ComponentType id) const; + + /** + * @param id Get entity system for this component type + * @param es receives entity system if found + * @return true if entity system was found + */ + template + bool GetEntitySystem(ComponentType id, T*& es) const; + + template + bool GetES(T*& es) const; + + /** + * Fill vector with all entity systems registered with + * the entity manager + */ + void GetEntitySystems(std::vector& toFill); + void GetEntitySystems(std::vector& toFill) const; + + /** + * @param eid Get component of this entity + * @param t Get component with this component type + * @param component Receives component if found + * @param searchDerived If true, return component that inherits t if one exists. Inheritance + * is defined by return value of EntitySystem::GetBaseType + * @return true if component was found + */ + bool GetComponent(EntityId eid, ComponentType t, Component*& component, bool searchDerived = false); + + /** + * @param eid Get component of this entity + * @param component Receives component of type T if found + * @param searchDerived If true, return component that inherits t if one exists. Inheritance + * is defined by return value of EntitySystem::GetBaseType + * @return true if success + */ + template + bool GetComponent(EntityId eid, T*& component, bool searchDerived = false); + + /** + * Get all components of given entity + * Warning: slow. Iterates over all entity systems. + * @param eid Get components of this entity + * @param toFill receives components + */ + void GetComponents(EntityId eid, std::vector& toFill); + void GetComponents(EntityId eid, std::vector& toFill) const; + + /** + * @param eid Check if component exists for this entity + * @param t Type of component to check for + * @param searchDerived If true, search for component that inherits t. Inheritance + * is defined by return value of EntitySystem::GetBaseType + * @return true if exists + */ + bool HasComponent(EntityId eid, ComponentType t, bool searchDerived = false) const; + + /** + * Create a component of given type for entity + * @param eid Add component to this entity + * @param id Add component of this type + * @param component Receives newly created component if success + * @return true if success + */ + bool CreateComponent(EntityId eid, ComponentType id, Component*& component); + + /** + * Create a component of given type for entity + * @param eid Add component to this entity + * @param component Receives newly created component of type T if success + * @return true if success + */ + template + bool CreateComponent(EntityId eid, T*& component); + + /** + * Delete component. + */ + bool DeleteComponent(EntityId eid, Component& component); + + /** + * Delete component. + */ + bool DeleteComponent(EntityId eid, ComponentType componentType); + + /** + * @return default message pump for inter-system communication + */ + MessagePump& GetMessagePump() + { + return mMessagePump; + } + + + // See messagepump.h for documentation + inline void RegisterForMessages(MessageType msgtype, const MessageFunctor& ftr, unsigned int options = FilterOptions::DEFAULT, const std::string& funcname = "") + { + mMessagePump.RegisterForMessages(msgtype, ftr, options, funcname); + } + + // See messagepump.h for documentation + inline void RegisterForMessages(MessageType msgtype, const MessageFunctor& ftr, const std::string& funcname) + { + mMessagePump.RegisterForMessages(msgtype, ftr, FilterOptions::DEFAULT, funcname); + } + + // See messagepump.h for documentation + inline bool UnregisterForMessages(MessageType msgtype, const MessageFunctor& ftr) + { + return mMessagePump.UnregisterForMessages(msgtype, ftr); + } + + // See messagepump.h for documentation + inline void EmitMessage(const Message& msg) + { + mMessagePump.EmitMessage(msg); + } + + // See messagepump.h for documentation + inline void EnqueueMessage(const Message& msg, double time = 0) + { + mMessagePump.EnqueueMessage(msg, time); + } + + // See messagepump.h for documentation + void EmitQueuedMessages(double simtime) + { + mMessagePump.EmitQueuedMessages(simtime); + } + + void AddDeletedCallback(ComponentDeletedCallback* cb); + bool RemoveDeletedCallback(ComponentDeletedCallback* cb); + + void AddEntitySystemRequestCallback(EntitySystemRequestCallback* cb); + bool RemoveEntitySystemRequestCallback(EntitySystemRequestCallback* cb); + + + private: + + // Returns next id and increments internal counter + EntityId GetNextAvailableID(); + + unsigned int mNextAvailableId; + + /** + * Look in type hierarchy map if a component derived from type exists + */ + bool GetDerived(EntityId eid, ComponentType ctype, Component*& comp) const; + + // storage for entity objects. + typedef std::map EntityMap; + EntityMap mEntities; + + // controls access to mEntities. + mutable OpenThreads::ReadWriteMutex mEntityMutex; + + // Storage for entity systems + typedef std::map EntitySystemStore; + EntitySystemStore mEntitySystemStore; + + // stores inheritance tree for component types + typedef std::multimap TypeHierarchyMap; + TypeHierarchyMap mTypeHierarchy; + + // for publish-subscribe of messages + MessagePump mMessagePump; + + ComponentDeletedCallbacks mDeletedCallbacks; + + EntitySystemRequestCallbacks mEntitySystemRequestCallbacks; + + }; + + + //////////////////////////////////////////////////////////////////////////////// + template + bool EntityManager::CreateComponent(EntityId eid, T*& component) + { + assert(eid > 0); + Component* c; + if(!this->CreateComponent(eid, T::TYPE, c)) + { + component = NULL; + return false; + } + component = static_cast(c); + return true; + } + + + //////////////////////////////////////////////////////////////////////////////// + template + bool EntityManager::GetComponent(EntityId eid, T*& component, bool searchDerived) + { + Component* c; + if(this->GetComponent(eid, T::TYPE, c, searchDerived)) + { + assert(dynamic_cast(c) != NULL); + component = static_cast(c); + return true; + } + component = NULL; + return false; + + } + + //////////////////////////////////////////////////////////////////////////////// + template + bool EntityManager::GetEntitySystem(ComponentType id, T*& es) const + { + EntitySystem* s = GetEntitySystem(id); + es = NULL; + if(s == NULL) return false; + assert(dynamic_cast(s) != NULL); + es = static_cast(s); + + return true; + } + + //////////////////////////////////////////////////////////////////////////////// + template + bool EntityManager::GetES(T*& es) const + { + ComponentType ctype = T::TYPE; + EntitySystemStore::const_iterator i = mEntitySystemStore.find(ctype); + if(i == mEntitySystemStore.end()) + { + es = NULL; + return false; + } + EntitySystem* s = i->second; + assert(dynamic_cast(s) != NULL); + es = static_cast(s); + return true; + } + +} diff --git a/external/dtEntity/include/dtEntity/entitysystem.h b/external/dtEntity/include/dtEntity/entitysystem.h new file mode 100644 index 000000000..ab9dbcc7d --- /dev/null +++ b/external/dtEntity/include/dtEntity/entitysystem.h @@ -0,0 +1,155 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include + +namespace dtEntity +{ + class Component; + class EntityManager; + + + /** + * Each entity system holds a number of components. + * Entity systems are themselves responsible for allocating and destroying + * their components. + */ + class EntitySystem + : public PropertyContainer + { + public: + + /** + * Constructor. + * @param id The type id of the component + * @param em The entity manager that this system belongs to + * @param baseType If component class is derived from component of another entity system then + * set the parent component type here. EntityManager::GetComponent will return + * components of this entity system when base type is requested. + */ + EntitySystem(EntityManager& em, ComponentType baseType = StringId()) + : mBaseType(baseType) + , mEntityManager(&em) + { + } + + virtual ~EntitySystem() + { + } + + /** + * @return The type id of the component that this system handles + */ + virtual ComponentType GetComponentType() const = 0; + /** + * @return If component class is derived from a base component type, give base + * type here + */ + ComponentType GetBaseType() const + { + return mBaseType; + } + + /** + * @return true if a component for this entity exists in the system + */ + virtual bool HasComponent(EntityId eid) const { return false; } + + /** + * @param eid Get component for the entity with this id + * @param component Receives the component if found + * @return true if found + */ + virtual bool GetComponent(EntityId eid, Component*& component) { return false; } + virtual bool GetComponent(EntityId eid, const Component*& component) { return false; } + + /** + * @param eid Create a component for the entity with this id. + * @param component Receives the component if it was succesfully created + * @return true if success + */ + virtual bool CreateComponent(EntityId eid, Component*& component) { return false; } + + /** + * Delete component. It is best to not call this directly but instead use + * the method EntityManager::DeleteComponent. Calling this method + * directly will not execute the component deletion callbacks, which + * can result in wrappers for that component not being invalidated + * + * @param eid Delete component for entity with this id + * @return true if entity had a component of this type + */ + virtual bool DeleteComponent(EntityId eid) { return false; } + + /** + * Put ids of all entities registered with this system into toFill + */ + virtual void GetEntitiesInSystem(std::list& toFill) const { } + + /** + * Get property names and default property values of component. Used + * for spawner creation + */ + virtual GroupProperty GetComponentProperties() const { return GroupProperty(); } + + /** + * @return entity manager that the entity system was added to + */ + EntityManager& GetEntityManager() const + { + return *mEntityManager; + } + + /** overwrite to react to add to entity manager */ + virtual void OnAddedToEntityManager(dtEntity::EntityManager& em) {} + virtual void OnRemoveFromEntityManager(dtEntity::EntityManager& em) {} + + /** + * Override this if components of this entity system should not + * be stored to map + */ + virtual bool StoreComponentToMap(dtEntity::EntityId) const { return true; } + + /** + * Override to return false if no spawner should be allowed to spawn this component + */ + virtual bool AllowComponentCreationBySpawner() const { return true; } + + /** + * Override this if properties of this entity system should + * be stored to scene file + */ + virtual bool StorePropertiesToScene() const { return false; } + + private: + + // no copy ctor + EntitySystem(EntitySystem&); + + ComponentType mBaseType; + EntityManager* mEntityManager; + }; +} diff --git a/external/dtEntity/include/dtEntity/export.h b/external/dtEntity/include/dtEntity/export.h new file mode 100644 index 000000000..9c209c62c --- /dev/null +++ b/external/dtEntity/include/dtEntity/export.h @@ -0,0 +1,40 @@ +#pragma once + +/* + * dtEntity Game and Simulation Engine + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library 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 Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Martin Scheffler + */ + +#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) +# ifdef DT_ENTITY_LIBRARY +# define DT_ENTITY_EXPORT __declspec(dllexport) +# else +# define DT_ENTITY_EXPORT __declspec(dllimport) +# endif +#else +# ifdef DT_ENTITY_LIBRARY +# define DT_ENTITY_EXPORT __attribute__ ((visibility("default"))) +# else +# define DT_ENTITY_EXPORT +# endif +#endif + +#ifdef _WIN32 +# pragma warning (disable: 4251) +# pragma warning(disable : 4355) // 'this' used in initializer list +#endif diff --git a/external/dtEntity/include/dtEntity/hash.h b/external/dtEntity/include/dtEntity/hash.h new file mode 100644 index 000000000..c9656f71b --- /dev/null +++ b/external/dtEntity/include/dtEntity/hash.h @@ -0,0 +1,39 @@ +//----------------------------------------------------------------------------- +// MurmurHash3 was written by Austin Appleby, and is placed in the public +// domain. The author hereby disclaims copyright to this source code. + +#ifndef _MURMURHASH3_H_ +#define _MURMURHASH3_H_ + +#include + +//----------------------------------------------------------------------------- +// Platform-specific functions and macros + +// Microsoft Visual Studio + +#if defined(_MSC_VER) +#if _MSC_VER < 1900 +typedef unsigned char uint8_t; +typedef unsigned long uint32_t; +typedef unsigned __int64 uint64_t; +#endif +// Other compilers + +#else // defined(_MSC_VER) + +#include + +#endif // !defined(_MSC_VER) + +//----------------------------------------------------------------------------- + +void MurmurHash3_x86_32 ( const void * key, int len, uint32_t seed, void * out ); + +void MurmurHash3_x86_128 ( const void * key, int len, uint32_t seed, void * out ); + +void MurmurHash3_x64_128 ( const void * key, int len, uint32_t seed, void * out ); + +//----------------------------------------------------------------------------- + +#endif // _MURMURHASH3_H_ diff --git a/external/dtEntity/include/dtEntity/init.h b/external/dtEntity/include/dtEntity/init.h new file mode 100644 index 000000000..11fa0077b --- /dev/null +++ b/external/dtEntity/include/dtEntity/init.h @@ -0,0 +1,53 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include + +namespace dtEntity +{ + class EntityManager; + + class DT_ENTITY_EXPORT ConsoleLogHandler + : public LogListener + { + public: + virtual void LogMessage(dtEntity::LogLevel::e level, const std::string& filename, const std::string& methodname, int linenumber, + const std::string& msg); + }; + + /** + * adds required entity systems to entity manager, including map, camera, layer, layerattachpoint. + * Registers a number of factories for entity systems that should be started lazily. + * Creates application system, passes it the viewer and installs update callback of app system to scene node. + * @param argc number of command line args + * @param standard c command line args + * @param em a valid entity manager + */ + void DT_ENTITY_EXPORT AddDefaultEntitySystemsAndFactories(int argc, char** argv, dtEntity::EntityManager& em); + + /** + * sets osg data paths from command line args or environment variables + */ + bool DT_ENTITY_EXPORT SetupDataPaths(int argc, char** argv, bool checkPaths); +} + diff --git a/external/dtEntity/include/dtEntity/inputinterface.h b/external/dtEntity/include/dtEntity/inputinterface.h new file mode 100644 index 000000000..7c15e695b --- /dev/null +++ b/external/dtEntity/include/dtEntity/inputinterface.h @@ -0,0 +1,175 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include + +namespace dtEntity +{ + + //////////////////////////////////////////////////////////////////////////////// + namespace TouchPhase + { + enum e + { + UNKNOWN, + BEGAN, + MOVED, + STATIONARY, + ENDED + }; + + std::string ToString(e v); + } + + //////////////////////////////////////////////////////////////////////////////// + struct DT_ENTITY_EXPORT TouchPoint + { + unsigned int mId; + float mX; + float mY; + unsigned int mTapCount; + TouchPhase::e mTouchPhase; + }; + + //////////////////////////////////////////////////////////////////////////////// + class InputCallbackInterface + { + public: + virtual ~InputCallbackInterface() {} + + virtual bool KeyUp(const std::string& name, bool handled, unsigned int contextid) { return false; } + virtual bool KeyDown(const std::string& name, bool handled, unsigned int contextid) { return false; } + virtual bool MouseButtonUp(int button, bool handled, unsigned int contextid) { return false; } + virtual bool MouseButtonDown(int button, bool handled, unsigned int contextid) { return false; } + virtual bool MouseWheel(int dir, bool handled, unsigned int contextid) { return false; } + virtual bool MouseMove(float x, float y, bool handled, unsigned int contextid) { return false; } + + virtual void MouseEnterLeave(bool focused, unsigned int contextid) {} + }; + + //////////////////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT InputInterface + { + public: + + static const StringId MouseXId; + static const StringId MouseYId; + static const StringId MouseXRawId; + static const StringId MouseYRawId; + static const StringId MouseDeltaXId; + static const StringId MouseDeltaYId; + static const StringId MouseDeltaXRawId; + static const StringId MouseDeltaYRawId; + + virtual ~InputInterface() {} + + /** + * Stores if current system is multitouch-capable + */ + virtual bool GetMultiTouchEnabled() const = 0; + virtual void SetMultiTouchEnabled(bool v) = 0; + + /** get or set if mouse cursor should be locked in + * center of screen (for FPS style steering) + */ + virtual bool GetLockCursor() const = 0; + virtual void SetLockCursor(bool v) = 0; + + /** + * Multitouch interface: return number of touch points + */ + virtual size_t GetNumTouches() const = 0; + + /** + * Multitouch interface: return touch points + */ + virtual std::vector GetTouches() const = 0; + + /** + * Return true if key is pressed, else false + */ + virtual bool GetKey(const std::string& name, unsigned int contextId = 0) const = 0; + + /** + * Return true if key was released this frame, else false + */ + virtual bool GetKeyUp(const std::string& name, unsigned int contextId = 0) const = 0; + + /** + * Return true if key was pressed down this frame, else false + */ + virtual bool GetKeyDown(const std::string& name, unsigned int contextId = 0) const = 0; + + /** + * Returns true if any keyboard key is currently pressed + */ + virtual bool AnyKeyDown() const = 0; + + /** + * Return string entered this frame + */ + virtual std::string GetInputString() const = 0; + + /** + * Return true if given mouse button is currently pressed. + * 0 for left button, 1 for right, 2 for center + */ + virtual bool GetMouseButton(int button, unsigned int contextId = 0) const = 0; + + /** + * Return true if given mouse button was pressed this frame. + * 0 for left button, 1 for right, 2 for center + */ + virtual bool GetMouseButtonDown(int button, unsigned int contextId = 0) const = 0; + + /** + * Return true if given mouse button was released this frame. + * 0 for left button, 1 for right, 2 for center + */ + virtual bool GetMouseButtonUp(int button, unsigned int contextId = 0) const = 0; + + /** + * Return axis value from -1 to 1 + * @TODO: Axes are currently hard coded + */ + virtual double GetAxis(StringId axisname) const = 0; + + /** + * Return current mouse wheel state. -1 = down, 1 = up, 0 = no motion + */ + virtual int GetMouseWheelState(unsigned int contextId = 0) const = 0; + + virtual void AddInputCallback(InputCallbackInterface*) = 0; + virtual bool RemoveInputCallback(InputCallbackInterface*) = 0; + + /** + * Return a list containing names of all registered keys + */ + virtual void GetKeyNames(std::map&) const = 0; + + }; + +} + diff --git a/external/dtEntity/include/dtEntity/log.h b/external/dtEntity/include/dtEntity/log.h new file mode 100644 index 000000000..37cc2ec88 --- /dev/null +++ b/external/dtEntity/include/dtEntity/log.h @@ -0,0 +1,57 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include + +#define DT_LOG_SOURCE __FILE__, __FUNCTION__, __LINE__ + +#define LOG_DEBUG(msg)\ +{\ + std::ostringstream os; os << msg; \ + dtEntity::LogManager::GetInstance().LogMessage(dtEntity::LogLevel::LVL_DEBUG, __FILE__, __FUNCTION__, __LINE__, os.str());\ +}\ + +#define LOG_INFO(msg)\ +{\ + std::ostringstream os; os << msg; \ + dtEntity::LogManager::GetInstance().LogMessage(dtEntity::LogLevel::LVL_INFO, __FILE__, __FUNCTION__, __LINE__, os.str());\ +}\ + +#define LOG_WARNING(msg)\ +{\ + std::ostringstream os; os << msg; \ + dtEntity::LogManager::GetInstance().LogMessage(dtEntity::LogLevel::LVL_WARNING, __FILE__, __FUNCTION__, __LINE__, os.str());\ +}\ + +#define LOG_ERROR(msg)\ +{\ + std::ostringstream os; os << msg; \ + dtEntity::LogManager::GetInstance().LogMessage(dtEntity::LogLevel::LVL_ERROR, __FILE__, __FUNCTION__, __LINE__, os.str());\ +}\ + +#define LOG_ALWAYS(msg)\ +{\ + std::ostringstream os; os << msg; \ + dtEntity::LogManager::GetInstance().LogMessage(dtEntity::LogLevel::LVL_ALWAYS, __FILE__, __FUNCTION__, __LINE__, os.str());\ +}\ + diff --git a/external/dtEntity/include/dtEntity/logmanager.h b/external/dtEntity/include/dtEntity/logmanager.h new file mode 100644 index 000000000..1ed726729 --- /dev/null +++ b/external/dtEntity/include/dtEntity/logmanager.h @@ -0,0 +1,80 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include +#include + +namespace dtEntity +{ + //////////////////////////////////////////////////////////////////////////////// + namespace LogLevel + { + enum e + { + LVL_ALWAYS, + LVL_ERROR, + LVL_DEBUG, + LVL_WARNING, + LVL_INFO + }; + } + + //////////////////////////////////////////////////////////////////////////////// + class LogListener + : public osg::Referenced + { + public: + virtual void LogMessage(LogLevel::e level, const std::string& filename, const std::string& methodname, int linenumber, + const std::string& msg) = 0; + + protected: + virtual ~LogListener() { } + }; + + //////////////////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT LogManager + : public dtEntity::Singleton + { + public: + + typedef std::vector > Listeners; + + void LogMessage(LogLevel::e level, const std::string& filename, const std::string& methodname, int linenumber, + const std::string& msg) const; + + void AddListener(LogListener* l); + void RemoveListener(LogListener* l); + + Listeners::size_type GetNumListeners() const; + LogListener* GetListener(Listeners::size_type index) const; + + private: + Listeners mListeners; + mutable OpenThreads::Mutex mMutex; + }; + +} diff --git a/external/dtEntity/include/dtEntity/mapcomponent.h b/external/dtEntity/include/dtEntity/mapcomponent.h new file mode 100644 index 000000000..16e9ccc8d --- /dev/null +++ b/external/dtEntity/include/dtEntity/mapcomponent.h @@ -0,0 +1,372 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace dtEntity +{ + struct MapData + { + std::string mMapPath; + std::string mDataPath; + unsigned int mSaveOrder; + + MapData(const std::string& mappath, const std::string& datapath, unsigned int order) + : mMapPath(mappath) + , mDataPath(datapath) + , mSaveOrder(order) + { + } + }; + + //////////////////////////////////////////////////////////////////////////////// + + /** + * The map component holds information about the entity and how to + * serialize it. + */ + class DT_ENTITY_EXPORT MapComponent : public Component + { + + public: + + static const ComponentType TYPE; + static const StringId EntityNameId; + static const StringId SpawnerNameId; + static const StringId MapNameId; + static const StringId UniqueIdId; + static const StringId SaveWithMapId; + static const StringId VisibleInEntityListId; + + MapComponent(); + virtual ~MapComponent(); + + virtual ComponentType GetType() const { return TYPE; } + + virtual void OnAddedToEntity(Entity& entity) { mOwner = &entity; } + + /** + * string identifier of entity. Does not need to be unique. Mainly used + * for debugging purposes + */ + std::string GetEntityName() const; + void SetEntityName(const std::string& v); + + /** + * If entity was created from a spawner then this is set to the spawners name. + * If string is empty then entity was not created by spawner. + */ + std::string GetSpawnerName() const; + void SetSpawnerName(const std::string& v); + + /** + * @return the spawner the entity was created from or NULL + * if entity was not created from spawner + */ + Spawner* GetSpawner() const; + + /** + * name of map that entity was loaded from and that it will be stored to + * if map is saved + */ + std::string GetMapName() const { return mMapName.Get(); } + void SetMapName(const std::string& v) { mMapName.Set(v); } + + /** + * A unique identifier identifying the entity. May be a random string. + */ + std::string GetUniqueId() const { return mUniqueIdStr; } + void SetUniqueId(const std::string& v); + + std::string GetDescription() const { return mDescription; } + void SetDescription(const std::string& v) { mDescription = v; } + + + void SetSaveWithMap(bool v) { mSaveWithMap.Set(v); } + bool GetSaveWithMap() const { return mSaveWithMap.Get(); } + + void SetVisibleInEntityList(bool v) { mVisibleInEntityList.Set(v); } + bool GetVisibleInEntityList() const { return mVisibleInEntityList.Get(); } + + private: + DynamicStringProperty mEntityName; + StringProperty mMapName; + DynamicStringProperty mSpawnerNameProp; + DynamicStringProperty mUniqueId; + Spawner* mSpawner; + std::string mUniqueIdStr; + std::string mDescription; + std::string mEntityNameStr; + BoolProperty mSaveWithMap; + BoolProperty mVisibleInEntityList; + Entity* mOwner; + + }; + + //////////////////////////////////////////////////////////////////////////////// + + class DT_ENTITY_EXPORT MapSystem + : public DefaultEntitySystem + , public EntityManager::EntitySystemRequestCallback + { + public: + + friend class MapComponent; + static const ComponentType TYPE; + typedef DefaultEntitySystem BaseClass; + typedef std::map > SpawnerStorage; + + + MapSystem(EntityManager& em); + ~MapSystem(); + + // overridden to check for uniqueness of unique id + virtual bool CreateComponent(EntityId eid, Component*& component); + virtual bool DeleteComponent(EntityId eid); + + virtual void OnAddedToEntityManager(dtEntity::EntityManager& em); + + + /** + * Get entity id by unique id. Useful for communicating with the outside world + */ + EntityId GetEntityIdByUniqueId(const std::string& name) const; + + /** + * If entity with this name exists, assign its entity object to &entity and return true. + * Else return false. + */ + bool GetEntityByUniqueId(const std::string& name, Entity*& entity) const; + + // reacts to SpawnEntityMessage + void OnSpawnEntity(const Message& msg); + + // reacts to DeleteEntityMessage + void OnDeleteEntity(const Message& msg); + + // reacts to StopSystemMessage by removing map system from entity manager + void OnStopSystem(const Message& msg); + + /** + * Causes a message EntityAddedToSceneMessage to be fired. + * Layer system reacts to this by adding assigned node to + * scene graph + * @param eid Id of entity to add to scene + * @return true if success + */ + bool AddToScene(EntityId eid); + + /** + * Causes a EntityRemovedFromSceneMessage to be fired. + * Layer system removes attached node from scene graph. + * @param eid Id of entity to remove from scene + * @return true if success + */ + bool RemoveFromScene(EntityId eid); + + /** + * Register spawner. EntityManager takes ownership of spawner. + * @threadsafe + */ + void AddSpawner(Spawner& spawner); + + /** + * Remove spawner registered by this name and delete it. + * @return true if spawner was registered under this name + * @threadsafe + */ + bool DeleteSpawner(const std::string& name); + + /** + * if spawner is registered under this name, assign it to + * @param spawner receives spawner + * @return true if success + * @threadsafe + */ + bool GetSpawner(const std::string& name, Spawner*& spawner) const; + + /** + * fill up a map with all spawners indexed by their name + * @threadsafe + */ + void GetAllSpawners(std::map& toFill) const; + + /** + * fill up a list with names of all registered spawners + * @threadsafe + */ + void GetAllSpawnerNames(std::vector& toFill) const; + + /** + * Call spawner to let it set up entity + * @param name Name of spawner + * @param spawned A valid, created entity + * @return true if success + * @threadsafe + */ + bool Spawn(const std::string& name, Entity& spawned) const; + + void GetSpawnerCreatedEntities(const std::string& spawnername, std::vector& ids, bool recursive = true) const; + + /** + * @return true if entity exists and was spawned by spawner or one of its child spawners + */ + bool IsSpawnOf(EntityId, const std::string& spawnername) const; + + /** + * Load scene from map file, start and configure entity systems + * as appropriate, load maps + */ + bool LoadScene(const std::string& path); + + /** + * Unload all maps + */ + bool UnloadScene(); + + + /** + * Save entity system configurations to scene file, + * @param path Save scene file to this path + * @param saveAllMaps if set, save all currently loaded maps to map files + */ + bool SaveScene(const std::string& path, bool saveAllMaps = true); + + /** + * Return true if map is found in file system + */ + bool MapExists(const std::string& path); + + /** + * Load a single map + */ + bool LoadMap(const std::string& path); + + /** + * Unload a single map + */ + bool UnloadMap(const std::string& path); + + /** + *Get an index representing the order in which maps should be loaded / saved + * Maps with lowest values are loaded first + */ + unsigned int GetMapSaveOrder(const std::string& path); + void SetMapSaveOrder(const std::string& path, int); + + /** + * Delete instances that were created from given map + */ + bool DeleteEntitiesByMap(const std::string& mapName); + + /** + * Save a single map + */ + bool SaveMap(const std::string& path); + + /** + * Save a single map as a copy + */ + bool SaveMapAs(const std::string& path, const std::string& copyname); + + /** + * Add an empty, named map to system + */ + bool AddEmptyMap(const std::string& dataPath, const std::string& mapname); + + /** + * Check if a map of that name exists + */ + bool IsMapLoaded(const std::string& mapName) const; + + /** + * Get a list of all maps in system + */ + std::vector GetLoadedMaps() const; + + /** + * Get all entities that are stored to this map + */ + void GetEntitiesInMap(const std::string& mapname, std::vector& toFill) const; + + // implementation of EntityManager::EntitySystemRequestCallback interface + virtual bool CreateEntitySystem(EntityManager* em, ComponentType t); + + void AddMapEncoder(MapEncoder* ec); + + MapEncoder* GetEncoderForMap(const std::string& extension) const; + MapEncoder* GetEncoderForScene(const std::string& extension) const; + + private: + + /** + * called by component. Don't call, please set the property on + * the component instead + * returns true if change succeeded, false if an entity with this id already exists + */ + bool OnEntityChangedUniqueId(EntityId id, const std::string& oldUniqueId, const std::string& newUniqueid); + + + /** + * Handles SetComponentPropertiesMessage + */ + void OnSetComponentProperties(const Message& m); + + /** + * Handles SetSystemPropertiesMessage + */ + void OnSetSystemProperties(const Message& m); + + void EmitSpawnerDeleteMessages(MapSystem::SpawnerStorage& spawners, const std::string& path); + + typedef std::vector LoadedMaps; + LoadedMaps mLoadedMaps; + + // store spawners in a map + SpawnerStorage mSpawners; + + // functors for registering to messages + MessageFunctor mSpawnEntityFunctor; + MessageFunctor mDeleteEntityFunctor; + MessageFunctor mResetSystemFunctor; + MessageFunctor mStopSystemFunctor; + MessageFunctor mSetComponentPropertiesFunctor; + MessageFunctor mSetSystemPropertiesFunctor; + ComponentPluginManager mPluginManager; + + std::map mEntitiesByUniqueId; + + typedef std::vector MapEncoders; + MapEncoders mMapEncoders; + }; +} diff --git a/external/dtEntity/include/dtEntity/mapencoder.h b/external/dtEntity/include/dtEntity/mapencoder.h new file mode 100644 index 000000000..d59691062 --- /dev/null +++ b/external/dtEntity/include/dtEntity/mapencoder.h @@ -0,0 +1,48 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + + +namespace dtEntity +{ + /** + * Pure virtual interface for loading and saving scene data to maps + */ + class MapEncoder + { + + public: + + virtual ~MapEncoder() {} + + virtual bool LoadMapFromFile(const std::string& path) = 0; + + // empty destination means overwrite mapPath + virtual bool SaveMapToFile(const std::string& mapPath, const std::string& destination) = 0; + + virtual bool LoadSceneFromFile(const std::string& path) = 0; + virtual bool SaveSceneToFile(const std::string& path) = 0; + + virtual bool AcceptsMapExtension(const std::string& /*extension*/) const = 0; + virtual bool AcceptsSceneExtension(const std::string& /*extension*/) const = 0; + }; +} + diff --git a/external/dtEntity/include/dtEntity/message.h b/external/dtEntity/include/dtEntity/message.h new file mode 100644 index 000000000..7601bf297 --- /dev/null +++ b/external/dtEntity/include/dtEntity/message.h @@ -0,0 +1,90 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include + +namespace dtEntity +{ + + /** + * Pure virtual Message interface class. Holds a number of properties + */ + class DT_ENTITY_EXPORT Message + : public PropertyContainer + { + + public: + + /** + * Default Constructor. + */ + Message() + : mType(MessageType()) + { + } + + /** + * Constructor. + * @param type The unique class ID of the message class + */ + Message(MessageType type) + : mType(type) + { + assert(mType != dtEntity::StringId() && "No message type set!"); + } + + // DTor + virtual ~Message() + { + } + + /** + * @return class type id of message + */ + MessageType GetType() const { return mType; } + + /** + * Create a copy of the message on the heap. + * Example generic implementation: + * virtual Message* Clone() const { return CloneContainer(); } + */ + virtual Message* Clone() const { + assert(mType != StringId() && "Cannot clone a message without type!"); + return CloneContainer(); + } + + private: + + // no copy CTor + Message(const Message& other); + + MessageType mType; + }; + + // Functors of this type can be registered to receive messages of a specific type. + typedef fastdelegate::FastDelegate1< const Message&, void> MessageFunctor; + +} diff --git a/external/dtEntity/include/dtEntity/messagefactory.h b/external/dtEntity/include/dtEntity/messagefactory.h new file mode 100644 index 000000000..0c5a7b47e --- /dev/null +++ b/external/dtEntity/include/dtEntity/messagefactory.h @@ -0,0 +1,77 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include + +namespace dtEntity +{ + + class DT_ENTITY_EXPORT MessageFactory + : public Singleton + { + public: + + MessageFactory() {} + + /** + * Register a message type with the message factory + * The template parameter holds the message class to instantiate + * Usage example: + * mMessageFactory->RegisterMessageType(TickMessage::TYPE); + * @param mtype MessageType id of message + */ + //////////////////////////////////////////////////////////////////////////////// + template + void RegisterMessageType(MessageType mtype) + { + mMessageFactory.template RegisterType(mtype); + } + + /** + * fill up a vector with the types of all registered messages + */ + void GetRegisteredMessageTypes(std::vector& toFill); + + /** + * Create a message of given type. A message class has to be registered with + * RegisterMessageType before it can be instantiated with CreateMessage. + * Please note that you can simply create messages with 'new', this is + * just a factory for generic script- and tool-side access + * @param msgType type id of message class + * @param msg Receives newly created message. Ownership of the message object + * is transfered to caller - post your message or delete it! + * @return true if success - false if message type is not registered + */ + bool CreateMessage(MessageType msgType, Message*& msg) const; + + // not implemented + MessageFactory(const MessageFactory& other); + + private: + // factory for message objects + ObjectFactory mMessageFactory; + + }; +} diff --git a/external/dtEntity/include/dtEntity/messagepump.h b/external/dtEntity/include/dtEntity/messagepump.h new file mode 100644 index 000000000..d21b7948c --- /dev/null +++ b/external/dtEntity/include/dtEntity/messagepump.h @@ -0,0 +1,194 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include + +namespace dtEntity +{ + + + + //////////////////////////////////////////////////////////////////////////////// + + + namespace FilterOptions + { + /* These bits define the way a functor is registered to a message. + * When multiple functors are registered to a message type then they are called + * in the order of their PRIORITY (highest priority first). + * The UNREGISTERED bit has to be set to false. It is used internally to mark + * deregistered functors for removal. + * + * If SINGLE_SHOT is set then the functor is unregistered after it is called the first time. + * Registrants can register for local messages, network messages, or both. + * Message senders can send a message to local or network or both. + */ + enum e + { + PRIORITY_LOWEST = 0, + PRIORITY_DEFAULT = 1, + PRIORITY_HIGHER = 2, + PRIORITY_HIGHEST = 3, + ORDER_LATE = 0, + ORDER_DEFAULT = 1, + ORDER_EARLY = 2, + ORDER_EARLIEST = 3, + UNREGISTERED = (1<<3), + SINGLE_SHOT = (1<<4), + + DEFAULT = ORDER_DEFAULT + }; + } + + + //////////////////////////////////////////////////////////////////////////////// + + + /* + * Internal data structure for message registration + */ + struct MsgRegistryEntry + { + unsigned int mOptions; + MessageFunctor mFunctor; + StringId mFuncName; + }; + + struct FutureMessageEntry + { + double mTimeToPost; + Message* mMessage; + }; + + + + //////////////////////////////////////////////////////////////////////////////// + // pure virtual interface + class MessageReceiver + { + public: + ~MessageReceiver() {} + virtual void Receive(const dtEntity::Message& msg) = 0; + }; + + //////////////////////////////////////////////////////////////////////////////// + + + class DT_ENTITY_EXPORT MessagePump + : public MessageReceiver + { + public: + + // thread safe message queue. The int stores the sending options. + typedef ThreadSafeQueue MessageQueue; + typedef ThreadSafeQueue FutureMessageQueue; + + /** + * CTor + */ + MessagePump(); + + /** + * DTor + */ + virtual ~MessagePump(); + + /** + * Register a functor to be called when a message of given type is emitted. + * @param msgtype Type of message to register to + * @param ftr This functor is called when a message of msgtype is emitted + * @param options Option bits for registration (see FilterOptions comments) + * @param funcname name for debugging and profiling purposes + * + */ + virtual void RegisterForMessages(MessageType msgtype, const MessageFunctor &ftr, unsigned int options = FilterOptions::DEFAULT, const std::string& funcname = ""); + + /** + * Unregister functor from message + * @param msgtype Type of message to unregister from + * @param ftr Unregister this message + * @return true if success + */ + virtual bool UnregisterForMessages(MessageType msgtype, const MessageFunctor& ftr); + + /** + * returns true if functor is registered to message + */ + virtual bool IsRegistered(MessageType msgtype, const MessageFunctor& ftr); + + /** + * Immediately send a message to all registered functors + * Warning: beware of circular dependencies! + * @param msg The message to send + */ + void EmitMessage(const Message& msg); + + /** + * Enqueue message and emit it on next PreFrame event + * @param when Future simulation time that event should be emitted at + * ( 0 means emit immediately) + */ + void EnqueueMessage(const Message& msg); + void EnqueueMessage(const Message& msg, double when); + + // implement MessageReceiver interface + virtual void Receive(const dtEntity::Message& msg) + { + EnqueueMessage(msg); + } + + /** + * Emit all messages in message queue + */ + void EmitQueuedMessages(double simtime); + + /** + * Discard all queued messages + */ + void ClearQueue(); + + /** + * Unregister all functors + */ + void UnregisterAll(); + + protected: + + // Registry for message functors + typedef std::multimap MessageFunctorRegistry; + MessageFunctorRegistry mMessageFunctors; + + + // stores messages til next tick + MessageQueue mMessageQueue; + + FutureMessageQueue mFutureMessageQueue; + // stores messages until their time to post has come + std::list mFutureMessages; + + }; +} diff --git a/external/dtEntity/include/dtEntity/nodemasks.h b/external/dtEntity/include/dtEntity/nodemasks.h new file mode 100644 index 000000000..8a047e54f --- /dev/null +++ b/external/dtEntity/include/dtEntity/nodemasks.h @@ -0,0 +1,43 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +namespace dtEntity +{ + namespace NodeMasks + { + enum e + { + REFLECTION_SCENE = (1 << 0), // OSGOcean + REFRACTION_SCENE = (1 << 1), // OSGOcean + NORMAL_SCENE = (1 << 2), // OSGOcean + SURFACE_MASK = (1 << 3), // OSGOcean + SILT_MASK = (1 << 4), // OSGOcean + VISIBLE = (1 << 5), + PICKABLE = (1 << 6), + TERRAIN = (1 << 7), + CASTS_SHADOWS = (1 << 8), + RECEIVES_SHADOWS = (1 << 9), + MANIPULATOR = (1 << 10) + }; + } + +} diff --git a/external/dtEntity/include/dtEntity/objectfactory.h b/external/dtEntity/include/dtEntity/objectfactory.h new file mode 100644 index 000000000..2d886780a --- /dev/null +++ b/external/dtEntity/include/dtEntity/objectfactory.h @@ -0,0 +1,147 @@ +#pragma once + +/* + * dtEntity Game and Simulation Engine + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library 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 Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Matthew W. Campbell + */ + +#include +#include + +namespace dtEntity +{ + /** + * Templated function to provide a generic object construction + * utility. + */ + template + BaseType *construct() + { + return new DerivedType(); + } + + /** + * This class is a template object factory. It allows one to + * create any type of object as long as there is a common base + * class. The common base class is defined on a per-factory + * basis using the templated parameter BaseType. + * @note + * The ObjectFactory implementation only supports objects with + * a default constructor. It will not work with objects that + * only have named constructors. + */ + template > + class ObjectFactory + { + public: + + typedef UniqueIdTypeClass UniqueIdType; + typedef BaseTypeClass BaseType; + typedef ltCmpClass ltCmp; + + typedef BaseType *(*createObjectFunc)(); /// Function pointer type for functions creating objects. + typedef std::map ObjectMap; + typedef typename ObjectMap::iterator ObjTypeItor; + typedef typename ObjectMap::const_iterator ObjTypeItorConst; + ObjectFactory() {} // constructor + + + /** + * Registers a new type of object with the factory. + * @return false if the type is a duplicate. + */ + template + bool RegisterType(UniqueIdType id) + { + if (this->objectTypeMap.find(id) != this->objectTypeMap.end()) + { + return false; + } + + this->objectTypeMap[id] = &construct; + return true; + } + + /** + * Removes an existing object type from the factory's known list + * of object types. + */ + void RemoveType(UniqueIdType id) { + this->objectTypeMap.erase(id); + } + + /** + * Checks to see if the factory can create objects of the given type. + * @param id The type of object to check for. + * @return True if the type is supported, false otherwise. + */ + bool IsTypeSupported(UniqueIdType id) const + { + ObjTypeItorConst itor(this->objectTypeMap.find(id)); + if (itor != this->objectTypeMap.end()) + { + return true; + } + else + { + return false; + } + } + + /** + * Gets a list of types that this factory knows how to create. + */ + void GetSupportedTypes(std::vector &types) const + { + types.clear(); + for (ObjTypeItorConst itor=this->objectTypeMap.begin(); + itor != this->objectTypeMap.end(); ++itor) + { + types.push_back(itor->first); + } + } + + /** + * Creates a new object. + * @param id - Type of object to create. + * @return Returns a pointer to the newly created object or NULL if the given id has not been registered. + * @throw Exception is thrown if the factory does not know how to create + * the requested type. + */ + BaseType* CreateObject(const UniqueIdType id) const + { + ObjTypeItorConst itor(this->objectTypeMap.find(id)); + + // We cannot create a new object if we do not know what type it is + // so throw an exception. + if (itor == this->objectTypeMap.end()) + { + return 0; + } + + return (itor->second)(); + } + + const ObjectMap& GetMap() const { return objectTypeMap; } + + private: + ///Maps a unique id to a function pointer that when called creates an + ///object of the appropriate type. + ObjectMap objectTypeMap; + }; +} diff --git a/external/dtEntity/include/dtEntity/profile.h b/external/dtEntity/include/dtEntity/profile.h new file mode 100644 index 000000000..2d6c050a7 --- /dev/null +++ b/external/dtEntity/include/dtEntity/profile.h @@ -0,0 +1,137 @@ +#pragma once + +/*************************************************************************************************** +** +** profile.h +** +** Real-Time Hierarchical Profiling for Game Programming Gems 3 +** +** by Greg Hjelstrom & Byon Garrabrant +** +***************************************************************************************************/ +#include +#include +#include +/* +** A node in the Profile Hierarchy Tree +*/ +class CProfileNode { + +public: + CProfileNode( dtEntity::StringId name, CProfileNode * parent ); + ~CProfileNode( void ); + + CProfileNode * Get_Sub_Node( dtEntity::StringId name ); + + CProfileNode * Get_Parent( void ) { return Parent; } + CProfileNode * Get_Sibling( void ) { return Sibling; } + CProfileNode * Get_Child( void ) { return Child; } + + void Reset( void ); + void Call( void ); + bool Return( void ); + + const dtEntity::StringId Get_Name( void ) { return Name; } + int Get_Total_Calls( void ) { return TotalCalls; } + float Get_Total_Time( void ) { return TotalTime; } + +protected: + + dtEntity::StringId Name; + int TotalCalls; + float TotalTime; + dtEntity::Timer_t StartTime; + int RecursionCounter; + + CProfileNode * Parent; + CProfileNode * Child; + CProfileNode * Sibling; +}; + +/* +** An iterator to navigate through the tree +*/ +class CProfileIterator +{ +public: + // Access all the children of the current parent + void First(void); + void Next(void); + bool Is_Done(void); + bool Is_Root(void) { return (CurrentParent->Get_Parent() == 0); } + + void Enter_Child( int index ); // Make the given child the new parent + void Enter_Largest_Child( void ); // Make the largest child the new parent + void Enter_Parent( void ); // Make the current parent's parent the new parent + + // Access the current child + dtEntity::StringId Get_Current_Name( void ) { return CurrentChild->Get_Name(); } + int Get_Current_Total_Calls( void ) { return CurrentChild->Get_Total_Calls(); } + float Get_Current_Total_Time( void ) { return CurrentChild->Get_Total_Time(); } + + // Access the current parent + const dtEntity::StringId Get_Current_Parent_Name( void ) { return CurrentParent->Get_Name(); } + int Get_Current_Parent_Total_Calls( void ) { return CurrentParent->Get_Total_Calls(); } + float Get_Current_Parent_Total_Time( void ) { return CurrentParent->Get_Total_Time(); } + +protected: + + CProfileNode * CurrentParent; + CProfileNode * CurrentChild; + + CProfileIterator( CProfileNode * start ); + friend class CProfileManager; +}; + + +/* +** The Manager for the Profile system +*/ +class DT_ENTITY_EXPORT CProfileManager { +public: + static void Start_Profile( dtEntity::StringId name ); + static void Stop_Profile( void ); + + static void Reset( void ); + static void Increment_Frame_Counter( void ); + static int Get_Frame_Count_Since_Reset( void ) { return FrameCounter; } + static float Get_Time_Since_Reset( void ); + + static CProfileIterator * Get_Iterator( void ) { return new CProfileIterator( &Root ); } + static void Release_Iterator( CProfileIterator * iterator ) { delete iterator; } + + static void dumpRecursive(CProfileIterator* profileIterator, int spacing); + static void dumpAll(); +private: + static CProfileNode Root; + static CProfileNode* CurrentNode; + static int FrameCounter; + static dtEntity::Timer_t ResetTime; +}; + + +/* +** ProfileSampleClass is a simple way to profile a function's scope +** Use the PROFILE macro at the start of scope to time +*/ +class CProfileSample { +public: + CProfileSample( dtEntity::StringId name ) + { + CProfileManager::Start_Profile( name ); + } + + ~CProfileSample( void ) + { + CProfileManager::Stop_Profile(); + } +}; + +#ifdef _DEBUG +#define PROFILE( name ) CProfileSample __profile( name ) +#else +#define PROFILE( name ) +#endif + + + diff --git a/external/dtEntity/include/dtEntity/property.h b/external/dtEntity/include/dtEntity/property.h new file mode 100644 index 000000000..dfaf83c51 --- /dev/null +++ b/external/dtEntity/include/dtEntity/property.h @@ -0,0 +1,1017 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace dtEntity +{ + + typedef osg::Vec2f Vec2f; + typedef osg::Vec3f Vec3f; + typedef osg::Vec4f Vec4f; + typedef osg::Vec2d Vec2d; + typedef osg::Vec3d Vec3d; + typedef osg::Vec4d Vec4d; + typedef osg::Quat Quat; + typedef osg::Matrix Matrix; + + /** + * dtEntity::Property class is an abstract base class. Each implementation + * is a wrapper for a (more or less) primitive data type like int, string, bool. + * The methods ToString and FromString can be used for serialization and deserialization. + * The property class has a variable mDataType which is used to identify the type + * of the concrete implementation class. + */ + + /** + * The data type IDs identifying the various property types + */ + namespace DataType + { + enum e + { + UNKNOWN_ID = 0, + ARRAY, + BOOL, + DOUBLE, + FLOAT, + GROUP, + INT, + MATRIX, + QUAT, + STRING, + STRINGID, + UINT, + VEC2, + VEC3, + VEC4, + VEC2D, + VEC3D, + VEC4D + }; + + std::string DT_ENTITY_EXPORT ToString(e); + e DT_ENTITY_EXPORT FromString(const std::string&); + } + + // helper function to split string by char + std::vector DT_ENTITY_EXPORT split(const std::string &s, char delim); + + // Fwd declaration + class Property; + + // value type of array property + typedef std::vector PropertyArray; + + // value type of group property + typedef std::map PropertyGroup; + + /** + * Base class for properties. Implementations have to set the mDataType + * variable on construction. + */ + class DT_ENTITY_EXPORT Property + { + public: + + virtual ~Property() {} + + /** + * Get data type of this property + */ + virtual DataType::e GetDataType() const = 0; + + /** + * Create a copy of this property on the heap + */ + virtual Property* Clone() const = 0; + + /** + * Set values of this property from another property. + * Should always work if both properties have the same type, + * Casting between property types should be possible case by case. + * return true if value could be set. + */ + virtual bool SetFrom(const Property& other) = 0; + + /** + * Equality operator has to be provided. Is used to check if + * values were changed from their default at serialization time + */ + virtual bool operator==(const Property& other) const = 0; + + /** + * To and from string have to be supplied for the editor gui and + * possibly for map saving + */ + virtual const std::string StringValue() const = 0; + virtual void SetString(const std::string&) = 0; + + /** + * Get value of property interpreted as various types. + * These default implementations cause an assertion error in debug mode + * and return a null value in release mode. + */ + virtual PropertyArray ArrayValue() const + { + LOG_ERROR("Cannot convert " << DataType::ToString(GetDataType()) << " to an array value!"); + return PropertyArray(); + } + + virtual bool BoolValue() const + { + LOG_ERROR("Cannot convert " << DataType::ToString(GetDataType()) << " to a bool value!"); + return false; + } + + virtual char CharValue() const + { + LOG_ERROR("Cannot convert " << DataType::ToString(GetDataType()) << " to a char value!"); + return 0; + } + + virtual double DoubleValue() const + { + LOG_ERROR("Cannot convert " << DataType::ToString(GetDataType()) << " to a double value!"); + return 0.0; + } + + virtual float FloatValue() const + { + LOG_ERROR("Cannot convert " << DataType::ToString(GetDataType()) << " to a float value!"); + return 0.0f; + } + + virtual PropertyGroup GroupValue() const + { + LOG_ERROR("Cannot convert " << DataType::ToString(GetDataType()) << " to a group value!"); + return PropertyGroup(); + } + + virtual int IntValue() const + { + LOG_ERROR("Cannot convert " << DataType::ToString(GetDataType()) << " to an int value!"); + return 0; + } + + virtual Matrix MatrixValue() const + { + LOG_ERROR("Cannot convert " << DataType::ToString(GetDataType()) << " to a matrix value!"); + return Matrix(); + } + + virtual Quat QuatValue() const + { + LOG_ERROR("Cannot convert " << DataType::ToString(GetDataType()) << " to a quat value!"); + return Quat(); + } + + virtual StringId StringIdValue() const + { + LOG_ERROR("Cannot convert " << DataType::ToString(GetDataType()) << " to a StringId value!"); + return 0; + } + + virtual unsigned int UIntValue() const + { + LOG_ERROR("Cannot convert " << DataType::ToString(GetDataType()) << " to a UInt value!"); + return 0; + } + + virtual Vec2f Vec2Value() const + { + LOG_ERROR("Cannot convert " << DataType::ToString(GetDataType()) << " to a vec2 value!"); + return Vec2f(); + } + + virtual Vec3f Vec3Value() const + { + LOG_ERROR("Cannot convert " << DataType::ToString(GetDataType()) << " to a vec3 value!"); + return Vec3f(); + } + + virtual Vec4f Vec4Value() const + { + LOG_ERROR("Cannot convert " << DataType::ToString(GetDataType()) << " to a vec4 value!"); + return Vec4f(); + } + + virtual Vec2d Vec2dValue() const + { + LOG_ERROR("Cannot convert " << DataType::ToString(GetDataType()) << " to a vec2d value!"); + return Vec2d(); + } + + virtual Vec3d Vec3dValue() const + { + LOG_ERROR("Cannot convert " << DataType::ToString(GetDataType()) << " to a vec3d value!"); + return Vec3d(); + } + + virtual Vec4d Vec4dValue() const + { + LOG_ERROR("Cannot convert " << DataType::ToString(GetDataType()) << " to a vec4d value!"); + return Vec4d(); + } + + + virtual void SetArray(const PropertyArray&) + { + LOG_ERROR("Cannot set " << DataType::ToString(GetDataType()) << " to an array value!"); + } + + virtual void SetBool(bool) + { + LOG_ERROR("Cannot set " << DataType::ToString(GetDataType()) << " to an bool value!"); + } + + virtual void SetChar(char) + { + LOG_ERROR("Cannot set " << DataType::ToString(GetDataType()) << " to a char value!"); + } + + virtual void SetDouble(double) + { + LOG_ERROR("Cannot set " << DataType::ToString(GetDataType()) << " to a double value!"); + } + + virtual void SetFloat(float) + { + LOG_ERROR("Cannot set " << DataType::ToString(GetDataType()) << " to a float value!"); + } + + virtual void SetGroup(const PropertyGroup&) + { + LOG_ERROR("Cannot set " << DataType::ToString(GetDataType()) << " to a group value!"); + } + + virtual void SetInt(int) + { + LOG_ERROR("Cannot set " << DataType::ToString(GetDataType()) << " to an int value!"); + } + + virtual void SetMatrix(const Matrix&) + { + LOG_ERROR("Cannot set " << DataType::ToString(GetDataType()) << " to a matrix value!"); + } + + virtual void SetQuat(const Quat&) + { + LOG_ERROR("Cannot set " << DataType::ToString(GetDataType()) << " to a quat value!"); + } + + virtual void SetStringId(dtEntity::StringId) + { + LOG_ERROR("Cannot set " << DataType::ToString(GetDataType()) << " to a StringId value!"); + } + + virtual void SetUInt(unsigned int) + { + LOG_ERROR("Cannot set " << DataType::ToString(GetDataType()) << " to a uint value!"); + } + + virtual void SetVec2(const Vec2f&) + { + LOG_ERROR("Cannot set " << DataType::ToString(GetDataType()) << " to a vec2 value!"); + } + + virtual void SetVec3(const Vec3f&) + { + LOG_ERROR("Cannot set " << DataType::ToString(GetDataType()) << " to a vec3 value!"); + } + + virtual void SetVec4(const Vec4f&) + { + LOG_ERROR("Cannot set " << DataType::ToString(GetDataType()) << " to a vec4 value!"); + } + + virtual void SetVec2D(const Vec2d&) + { + LOG_ERROR("Cannot set " << DataType::ToString(GetDataType()) << " to a vec2d value!"); + } + + virtual void SetVec3D(const Vec3d&) + { + LOG_ERROR("Cannot set " << DataType::ToString(GetDataType()) << " to a vec3d value!"); + } + + virtual void SetVec4D(const Vec4d&) + { + LOG_ERROR("Cannot set " << DataType::ToString(GetDataType()) << " to a vec4d value!"); + } + + }; + + //////////////////////////////////////////////////////////////////////////////// + + /** + * holds an array of properties as pointers. + * Takes ownership of its properties: all properties are deleted in + * the destructor. + */ + class DT_ENTITY_EXPORT ArrayProperty : public Property + { + public: + ArrayProperty(const PropertyArray& v = PropertyArray()); + ~ArrayProperty(); + + typedef PropertyArray::size_type size_type; + + virtual DataType::e GetDataType() const { return DataType::ARRAY; } + + virtual PropertyArray ArrayValue() const; + virtual void SetArray(const PropertyArray& v) { Set(v); } + virtual const std::string StringValue() const; + virtual Vec2f Vec2Value() const; + virtual Vec3f Vec3Value() const; + virtual Vec4f Vec4Value() const; + virtual Vec2d Vec2dValue() const; + virtual Vec3d Vec3dValue() const; + virtual Vec4d Vec4dValue() const; + virtual Quat QuatValue() const; + virtual Matrix MatrixValue() const; + + const PropertyArray& Get() const { return mValue; } + + virtual Property* Clone() const ; + virtual bool operator==(const Property& other) const; + + void Set(const PropertyArray& v); + + // causes an assertion failure when called + virtual void SetString(const std::string&); + virtual void SetVec2(const Vec2f&); + virtual void SetVec3(const Vec3f&); + virtual void SetVec4(const Vec4f&); + virtual void SetVec2D(const Vec2d&); + virtual void SetVec3D(const Vec3d&); + virtual void SetVec4D(const Vec4d&); + + virtual bool SetFrom(const Property& other); + + /** + * Add to array. Ownership is taken by ArrayProperty - + * property is deleted in destructor + */ + void Add(Property* prop); + + /** + * Insert into array at given index. Ownership is taken by ArrayProperty - + * property is deleted in destructor + */ + void Insert(size_type index, Property* prop); + + /** + * @return property at given index + */ + Property* Get(size_type index); + const Property* Get(size_type index) const; + + /** + * Remove from array and delete prop + * Remove true if prop was found in array + */ + bool Remove(Property* prop); + + /** + * Delete all held properties + */ + void Clear(); + + size_type Size() const + { + return mValue.size(); + } + + private: + + PropertyArray mValue; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT BoolProperty : public Property + { + public: + BoolProperty(bool v = false); + + virtual DataType::e GetDataType() const { return DataType::BOOL; } + + virtual bool BoolValue() const; + virtual void SetBool(bool v) { Set(v); } + + virtual const std::string StringValue() const; + bool Get() const { return mValue; } + + virtual Property* Clone() const; + virtual bool operator==(const Property& other) const; + void Set(bool v) { mValue = v; } + virtual void SetString(const std::string&); + virtual bool SetFrom(const Property& other); + + private: + + bool mValue; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT DoubleProperty : public Property + { + public: + DoubleProperty(double v = 0); + + virtual DataType::e GetDataType() const { return DataType::DOUBLE; } + + virtual double DoubleValue() const; + virtual float FloatValue() const; + virtual unsigned int UIntValue() const; + virtual void SetDouble(double v) { Set(v); } + virtual void SetFloat(float v) { Set(v); } + virtual const std::string StringValue() const; + double Get() const { return mValue; } + virtual Property* Clone() const; + virtual bool operator==(const Property& other) const; + void Set(double v) { mValue = v; } + virtual void SetString(const std::string&); + virtual bool SetFrom(const Property& other); + + private: + double mValue; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT FloatProperty : public Property + { + public: + FloatProperty(float v = 0); + + virtual DataType::e GetDataType() const { return DataType::FLOAT; } + virtual float FloatValue() const; + virtual double DoubleValue() const; + virtual void SetFloat(float v) { Set(v); } + virtual void SetDouble(double v) { Set(static_cast(v)); } + virtual const std::string StringValue() const; + float Get() const { return mValue; } + + virtual Property* Clone() const; + virtual bool operator==(const Property& other) const; + void Set(float v) { mValue = v; } + virtual void SetString(const std::string&); + virtual bool SetFrom(const Property& other); + + private: + float mValue; + }; + + ////////////////////////////////////////////////////////////////// + /** + * Takes ownership of added properties, they are deleted in the + * destructor + */ + class DT_ENTITY_EXPORT GroupProperty : public Property + { + public: + GroupProperty(const PropertyGroup& v = PropertyGroup()); + ~GroupProperty(); + GroupProperty(const GroupProperty&); + + virtual DataType::e GetDataType() const { return DataType::GROUP; } + + void Clear(); + + virtual PropertyGroup GroupValue() const; + virtual void SetGroup(const PropertyGroup& v) { Set(v); } + virtual const std::string StringValue() const; + + const PropertyGroup& Get() const { return mValue; } + + // add prop and take ownership + void Add(StringId name, Property* prop); + virtual Property* Clone() const; + void operator=(const GroupProperty&); + bool operator==(const Property& other) const; + void operator+=(const GroupProperty& other); + void Set(const PropertyGroup& v); + virtual void SetString(const std::string&); + virtual bool SetFrom(const Property& other); + bool Empty() const; + Property* Get(StringId); + const Property* Get(StringId) const; + bool Has(StringId) const; + + protected: + PropertyGroup mValue; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT IntProperty : public Property + { + public: + IntProperty(int v = 0); + + virtual DataType::e GetDataType() const { return DataType::INT; } + + virtual int IntValue() const; + virtual void SetInt(int v) { Set(v); } + virtual unsigned int UIntValue() const; + virtual void SetUInt(unsigned int v) { Set(static_cast(v)); } + + virtual float FloatValue() const; + virtual double DoubleValue() const; + virtual void SetDouble(double); + virtual void SetFloat(float); + virtual const std::string StringValue() const; + int Get() const { return mValue; } + + virtual Property* Clone() const; + virtual bool operator==(const Property& other) const; + void Set(int v) { mValue = v; } + virtual void SetString(const std::string&); + virtual bool SetFrom(const Property& other); + private: + int mValue; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT MatrixProperty : public Property + { + public: + MatrixProperty(const Matrix& v = Matrix()); + + virtual DataType::e GetDataType() const { return DataType::MATRIX; } + + virtual Matrix MatrixValue() const; + virtual void SetMatrix(const Matrix& v) { Set(v); } + virtual const std::string StringValue() const; + const Matrix& Get() const { return mValue; } + + virtual Property* Clone() const; + virtual bool operator==(const Property& other) const; + void Set(const Matrix& v) { mValue = v; } + virtual void SetString(const std::string&); + virtual bool SetFrom(const Property& other); + + private: + + Matrix mValue; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT QuatProperty : public Property + { + public: + QuatProperty(); + QuatProperty(const Quat& v); + QuatProperty(double x, double y, double z, double w); + QuatProperty(const double* v); + + virtual DataType::e GetDataType() const { return DataType::QUAT; } + + virtual Quat QuatValue() const; + virtual const std::string StringValue() const; + virtual void SetQuat(const Quat& v) { Set(v); } + + const Quat Get() const { return Quat(mValues[0], mValues[1], mValues[2], mValues[3]); } + + // warning: not sure if this is safe on all platforms + const Quat& GetAsQuat() const { return reinterpret_cast(mValues); } + + virtual Property* Clone() const; + virtual bool operator==(const Property& other) const; + + void Set(const Quat& v) + { + mValues[0] = v[0]; + mValues[1] = v[1]; + mValues[2] = v[2]; + mValues[3] = v[3]; + } + + void Set(const double* v) + { + mValues[0] = v[0]; + mValues[1] = v[1]; + mValues[2] = v[2]; + mValues[3] = v[3]; + } + + const double* GetValues() const { return mValues; } + + virtual void SetString(const std::string&); + virtual bool SetFrom(const Property& other); + + private: + + double mValues[4]; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT StringProperty : public Property + { + public: + StringProperty(const std::string& v = ""); + + virtual DataType::e GetDataType() const { return DataType::STRING; } + + virtual const std::string StringValue() const; + virtual StringId StringIdValue() const; + //virtual void SetStringId(dtEntity::StringId v) { Set(GetStringFromSID(v)); } + + const std::string Get() const { return mValue; } + + virtual Property* Clone() const; + virtual bool operator==(const Property& other) const; + void Set(const std::string& v) { mValue = v; } + virtual void SetString(const std::string&); + virtual bool SetFrom(const Property& other); + + private: + + std::string mValue; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT StringIdProperty : public Property + { + public: + StringIdProperty(StringId v = StringId()); + + virtual DataType::e GetDataType() const { return DataType::STRINGID; } + + virtual StringId StringIdValue() const; + virtual void SetStringId(dtEntity::StringId v) { Set(v); } + virtual const std::string StringValue() const; + StringId Get() const { return mValue; } + + virtual Property* Clone() const; + virtual bool operator==(const Property& other) const; + void Set(StringId v) { mValue = v; } + virtual void SetString(const std::string&); + virtual bool SetFrom(const Property& other); + + private: + + StringId mValue; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT UIntProperty : public Property + { + public: + UIntProperty(unsigned int v = 0); + + virtual DataType::e GetDataType() const { return DataType::UINT; } + + virtual unsigned int UIntValue() const; + virtual void SetUInt(unsigned int v) { Set(v); } + virtual int IntValue() const; + virtual float FloatValue() const; + virtual double DoubleValue() const; + virtual const std::string StringValue() const; + unsigned int Get() const { return mValue; } + + virtual Property* Clone() const; + virtual bool operator==(const Property& other) const; + void Set(unsigned int v) { mValue = v; } + virtual void SetString(const std::string&); + virtual void SetDouble(double); + virtual void SetFloat(float); + virtual bool SetFrom(const Property& other); + private: + unsigned int mValue; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT Vec2Property : public Property + { + public: + + Vec2Property(); + Vec2Property(const Vec2f& v); + Vec2Property(float x, float y); + Vec2Property(const float* vals); + + virtual DataType::e GetDataType() const { return DataType::VEC2; } + + virtual Vec2f Vec2Value() const; + virtual void SetVec2(const Vec2f& v) { Set(v); } + virtual Vec2d Vec2dValue() const; + virtual void SetVec2D(const Vec2d& v) { Set(v); } + + virtual const std::string StringValue() const; + const Vec2f Get() const { return Vec2f(mValues[0], mValues[1]); } + + // warning: not sure if this is safe on all platforms + const Vec2f& GetAsVec2() const { return reinterpret_cast(mValues); } + + virtual Property* Clone() const; + virtual bool operator==(const Property& other) const; + + void Set(const Vec2f& v) + { + mValues[0] = v[0]; + mValues[1] = v[1]; + } + + void Set(const float* v) + { + mValues[0] = v[0]; + mValues[1] = v[1]; + } + + virtual void SetString(const std::string&); + virtual bool SetFrom(const Property& other); + + const float* GetValues() const { return mValues; } + + private: + + float mValues[2]; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT Vec3Property : public Property + { + public: + Vec3Property(); + Vec3Property(const Vec3f& v); + Vec3Property(float x, float y, float z); + Vec3Property(const float* vals); + + virtual DataType::e GetDataType() const { return DataType::VEC3; } + + virtual Vec3f Vec3Value() const; + virtual void SetVec3(const Vec3f& v) { Set(v); } + virtual Vec3d Vec3dValue() const; + virtual void SetVec3D(const Vec3d& v) { Set(v); } + + virtual Vec2f Vec2Value() const; + virtual Vec2d Vec2dValue() const; + virtual const std::string StringValue() const; + const Vec3f Get() const { return Vec3f(mValues[0], mValues[1], mValues[2]); } + + // warning: not sure if this is safe on all platforms + const Vec3f& GetAsVec3() const { return reinterpret_cast(mValues); } + + virtual Property* Clone() const; + virtual bool operator==(const Property& other) const; + void Set(const Vec3f& v) + { + mValues[0] = v[0]; + mValues[1] = v[1]; + mValues[2] = v[2]; + } + + void Set(const float* v) + { + mValues[0] = v[0]; + mValues[1] = v[1]; + mValues[2] = v[2]; + } + + virtual void SetString(const std::string&); + virtual bool SetFrom(const Property& other); + + const float* GetValues() const { return mValues; } + + + private: + float mValues[3]; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT Vec4Property : public Property + { + public: + Vec4Property(); + Vec4Property(const Vec4f& v); + Vec4Property(float x, float y, float z, float w); + Vec4Property(const float* vals); + + virtual DataType::e GetDataType() const { return DataType::VEC4; } + + virtual Vec4f Vec4Value() const; + virtual void SetVec4(const Vec4f& v) { Set(v); } + virtual Vec4d Vec4dValue() const; + virtual void SetVec4D(const Vec4d& v) { Set(v); } + virtual const std::string StringValue() const; + + const Vec4f Get() const { return Vec4f(mValues[0], mValues[1], mValues[2], mValues[3]); } + + // warning: not sure if this is safe on all platforms + const Vec4f& GetAsVec4() const { return reinterpret_cast(mValues); } + + virtual Vec2f Vec2Value() const; + virtual Vec2d Vec2dValue() const; + virtual Vec3f Vec3Value() const; + virtual Vec3d Vec3dValue() const; + + virtual Property* Clone() const; + virtual bool operator==(const Property& other) const; + void Set(const Vec4f& v) + { + mValues[0] = v[0]; + mValues[1] = v[1]; + mValues[2] = v[2]; + mValues[3] = v[3]; + } + + void Set(const float* v) + { + mValues[0] = v[0]; + mValues[1] = v[1]; + mValues[2] = v[2]; + mValues[3] = v[3]; + } + + virtual void SetString(const std::string&); + virtual bool SetFrom(const Property& other); + + const float* GetValues() const { return mValues; } + + private: + float mValues[4]; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT Vec2dProperty : public Property + { + public: + + Vec2dProperty(); + Vec2dProperty(const Vec2d& v); + Vec2dProperty(double x, double y); + Vec2dProperty(const double* v); + + virtual DataType::e GetDataType() const { return DataType::VEC2D; } + + virtual Vec2f Vec2Value() const; + virtual void SetVec2(const Vec2f& v) { Set(v); } + virtual Vec2d Vec2dValue() const; + virtual void SetVec2D(const Vec2d& v) { Set(v); } + virtual const std::string StringValue() const; + const Vec2d Get() const { return Vec2d(mValues[0], mValues[1]); } + + // warning: not sure if this is safe on all platforms + const Vec2d& GetAsVec2d() const { return reinterpret_cast(mValues); } + + virtual Property* Clone() const; + virtual bool operator==(const Property& other) const; + void Set(const Vec2d& v) + { + mValues[0] = v[0]; + mValues[1] = v[1]; + } + + void Set(const double* v) + { + mValues[0] = v[0]; + mValues[1] = v[1]; + } + + virtual void SetString(const std::string&); + virtual bool SetFrom(const Property& other); + + const double* GetValues() const { return mValues; } + + private: + + double mValues[2]; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT Vec3dProperty : public Property + { + public: + + Vec3dProperty(); + Vec3dProperty(const Vec3d& v); + Vec3dProperty(double x, double y, double z); + Vec3dProperty(const double* v); + + virtual DataType::e GetDataType() const { return DataType::VEC3D; } + + virtual Vec3f Vec3Value() const; + virtual void SetVec3(const Vec3f& v) { Set(v); } + virtual Vec3d Vec3dValue() const; + virtual void SetVec3D(const Vec3d& v) { Set(v); } + virtual const std::string StringValue() const; + const Vec3d Get() const { return Vec3d(mValues[0], mValues[1], mValues[2]); } + + // warning: not sure if this is safe on all platforms + const Vec3d& GetAsVec3d() const { return reinterpret_cast(mValues); } + + virtual Vec2f Vec2Value() const; + virtual Vec2d Vec2dValue() const; + + virtual Property* Clone() const; + virtual bool operator==(const Property& other) const; + void Set(const Vec3d& v) + { + mValues[0] = v[0]; + mValues[1] = v[1]; + mValues[2] = v[2]; + } + + void Set(const double* v) + { + mValues[0] = v[0]; + mValues[1] = v[1]; + mValues[2] = v[2]; + } + + virtual void SetString(const std::string&); + virtual bool SetFrom(const Property& other); + + const double* GetValues() const { return mValues; } + + private: + double mValues[3]; + }; + + ////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT Vec4dProperty : public Property + { + public: + + Vec4dProperty(); + Vec4dProperty(const Vec4d& v); + Vec4dProperty(double x, double y, double z, double w); + Vec4dProperty(const double* v); + + virtual DataType::e GetDataType() const { return DataType::VEC4D; } + + virtual Vec4f Vec4Value() const; + virtual void SetVec4(const Vec4f& v) { Set(v); } + virtual Vec4d Vec4dValue() const; + virtual void SetVec4D(const Vec4d& v) { Set(v); } + virtual const std::string StringValue() const; + const Vec4d Get() const { return Vec4d(mValues[0], mValues[1], mValues[2], mValues[3]); } + + // warning: not sure if this is safe on all platforms + const Vec4d& GetAsVec2d() const { return reinterpret_cast(mValues); } + + virtual Vec2f Vec2Value() const; + virtual Vec2d Vec2dValue() const; + virtual Vec3f Vec3Value() const; + virtual Vec3d Vec3dValue() const; + + virtual Property* Clone() const; + virtual bool operator==(const Property& other) const; + void Set(const Vec4d& v) + { + mValues[0] = v[0]; + mValues[1] = v[1]; + mValues[2] = v[2]; + mValues[3] = v[3]; + } + + void Set(const double* v) + { + mValues[0] = v[0]; + mValues[1] = v[1]; + mValues[2] = v[2]; + mValues[3] = v[3]; + } + + virtual void SetString(const std::string&); + virtual bool SetFrom(const Property& other); + + const double* GetValues() const { return mValues; } + + private: + double mValues[4]; + }; + +} diff --git a/external/dtEntity/include/dtEntity/propertycontainer.h b/external/dtEntity/include/dtEntity/propertycontainer.h new file mode 100644 index 000000000..61c6419ec --- /dev/null +++ b/external/dtEntity/include/dtEntity/propertycontainer.h @@ -0,0 +1,147 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include + +namespace dtEntity +{ + class Property; + + /** + * Holds a number of properties. This container does NOT take ownership + * of properties, they are not deleted in the constructor. + */ + class DT_ENTITY_EXPORT PropertyContainer : public GroupProperty + { + public: + + PropertyContainer() {} + + virtual ~PropertyContainer() + { + // don't delete properties, they are not on heap + mValue.clear(); + } + +#if CALL_ONPROPERTYCHANGED_METHOD == 0 + // hide when compiling with new property system + private: +#endif + /** + * Can be overridden to react to changes of properties. + * Should be called by user when changing a property on the + * PropertyContainer. + */ + virtual void OnPropertyChanged(StringId propname, Property& prop) {} + + public: + + /** + * should be called when a set of interdependent + * properties were changed. + * The component can overwrite this method to react to these + * changes. + */ + virtual void Finished() {} + + /** + * template helper for creating Clone() methods + */ + template + T* CloneContainer() const; + + /** + * Copy property values from other to this + */ + void InitFrom(const PropertyContainer& other); + + /** + * Set value of property registered with given string id. + * In debug mode this throws an assertion when a component + * is set to a wrong type. + */ + void SetArray(StringId name, const std::vector& val); + void SetBool(StringId name, bool val); + void SetDouble(StringId name, double val); + void SetFloat(StringId name, float val); + void SetGroup(StringId name, const std::map& val); + void SetInt(StringId name, int val); + void SetMatrix(StringId name, const Matrix& val); + void SetQuat(StringId name, const Quat& val); + void SetString(StringId name, const std::string& val); + void SetStringId(StringId name, StringId val); + void SetUInt(StringId name, unsigned int val); + void SetVec2(StringId name, const Vec2f& val); + void SetVec3(StringId name, const Vec3f& val); + void SetVec4(StringId name, const Vec4f& val); + void SetVec2d(StringId name, const Vec2d& val); + void SetVec3d(StringId name, const Vec3d& val); + void SetVec4d(StringId name, const Vec4d& val); + + /** + * Return value of property registered with given string id + */ + std::vector GetArray(StringId name) const; + bool GetBool(StringId name) const; + double GetDouble(StringId name) const; + float GetFloat(StringId name) const; + std::map GetGroup(StringId name) const; + int GetInt(StringId name) const; + Matrix GetMatrix(StringId name) const; + Quat GetQuat(StringId name) const; + std::string GetString(StringId name) const; + StringId GetStringId(StringId name) const; + unsigned int GetUInt(StringId name) const; + Vec2f GetVec2(StringId name) const; + Vec3f GetVec3(StringId name) const; + Vec4f GetVec4(StringId name) const; + Vec2d GetVec2d(StringId name) const; + Vec3d GetVec3d(StringId name) const; + Vec4d GetVec4d(StringId name) const; + + protected: + + /** + * Register a property under the given string id + */ + void Register(StringId name, Property* prop); + + private: + + // no copy constructor + PropertyContainer(const PropertyContainer& other); + }; + + template + T* PropertyContainer::CloneContainer() const + { + T* ret = new T(); + ret->InitFrom(*this); + return ret; + } + +} diff --git a/external/dtEntity/include/dtEntity/rapidxmlmapencoder.h b/external/dtEntity/include/dtEntity/rapidxmlmapencoder.h new file mode 100644 index 000000000..a759a6b86 --- /dev/null +++ b/external/dtEntity/include/dtEntity/rapidxmlmapencoder.h @@ -0,0 +1,77 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include + +namespace dtEntity +{ + + class Spawner; + class MapSystem; + class Property; + + class DT_ENTITY_EXPORT RapidXMLMapEncoder + : public MapEncoder + { + + public: + + RapidXMLMapEncoder(EntityManager& em); + virtual ~RapidXMLMapEncoder(); + + virtual bool LoadMapFromFile(const std::string& path); + + // empty destination means overwrite mapPath + virtual bool SaveMapToFile(const std::string& mapPath, const std::string& destination = ""); + + virtual bool LoadSceneFromFile(const std::string& path); + + // empty dest means overwrite original file + virtual bool SaveSceneToFile(const std::string& path); + + virtual bool AcceptsMapExtension(const std::string& extension) const + { + return extension == "dtemap"; + } + + virtual bool AcceptsSceneExtension(const std::string& extension) const + { + return extension == "dtescene"; + } + + static dtEntity::Property* ParseProperty(rapidxml::xml_node<>* element); + + // create XML nodes for properties and add them to parent node + static void SerializeProperties(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* parent, const std::map& props); + + private: + + EntityManager* mEntityManager; + MapSystem* mMapSystem; + + }; +} + diff --git a/external/dtEntity/include/dtEntity/resourcemanager.h b/external/dtEntity/include/dtEntity/resourcemanager.h new file mode 100644 index 000000000..b51b5ad5e --- /dev/null +++ b/external/dtEntity/include/dtEntity/resourcemanager.h @@ -0,0 +1,87 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include + +namespace osg +{ + class Node; +} + +namespace dtEntity +{ + class EntityManager; + + namespace ResourceManagerOptions + { + enum e + { + DeepCopy = 1<<0, // If in cache: Create copy of node and all of its subnodes + ShallowCopy = 1<<1, // If in cache: Create copy of node, share subnodes of cached node + CopyNodes = 1<<2, // If in cache: Create copy of node and subnodes, share vertices, textures etc + CopyHardwareMeshes = 1<<3, // If in cache: Special mode for efficiently sharing osgAnimation objects + DoOptimization = 1<<4, // Run osgUtil::Optimizer on first load + Default = ShallowCopy + }; + } + + /////////////////////////////////////////////////////////////////////////// + class DT_ENTITY_EXPORT ResourceManager + : public dtEntity::Singleton + { + public: + + typedef std::map > NodeStore; + + /** + * Try to read node from data paths. + * @param path Load resource from this path + * @param options Loading options. + * @return node, NULL if not found + */ + osg::ref_ptr GetNode(EntityManager& em, const std::string& path, unsigned int options = ResourceManagerOptions::Default); + + /** + * @return true if this resource resides in the cache + */ + bool IsInNodeCache(const std::string& path); + + /** + * remove from cache + * @return true if this resource was in the cache + */ + bool RemoveFromNodeCache(const std::string& path); + + /** + * Call this method to notify the resource manager that this resource has changed + * and should be reloaded + */ + void TriggerReload(const std::string& path, EntityManager& em); + + private: + NodeStore mNodeStore; + }; +} diff --git a/external/dtEntity/include/dtEntity/scriptaccessor.h b/external/dtEntity/include/dtEntity/scriptaccessor.h new file mode 100644 index 000000000..8e557a93e --- /dev/null +++ b/external/dtEntity/include/dtEntity/scriptaccessor.h @@ -0,0 +1,53 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include + +namespace dtEntity +{ + + + typedef std::vector PropertyArgs; + typedef fastdelegate::FastDelegate1 ScriptMethodFunctor; + + class DT_ENTITY_EXPORT ScriptAccessor + { + public: + + virtual ~ScriptAccessor() { } + + void AddScriptedMethod(const std::string& methodname, const ScriptMethodFunctor& functor); + + // Caller is responsible for deleting the returned property! + Property* CallScriptedMethod(const std::string& methodname, const PropertyArgs& args) const; + + void GetMethodNames(std::vector& names) const; + + private: + std::map mFunctors; + }; +} + diff --git a/external/dtEntity/include/dtEntity/singleton.h b/external/dtEntity/include/dtEntity/singleton.h new file mode 100644 index 000000000..fa43ed06d --- /dev/null +++ b/external/dtEntity/include/dtEntity/singleton.h @@ -0,0 +1,73 @@ +#pragma once + +/* -*-c++-*- + * dtEntity Game and Simulation Engine + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library 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 Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Martin Scheffler + */ + + +namespace dtEntity +{ + /** simple singleton class. Not thread safe! + */ + template + class Singleton + { + public: + + static T& GetInstance() + { + if (mInstance == 0) + { + mInstance = new T; + } + + return *mInstance; + }; + + static void DestroyInstance() + { + if(mInstance != 0) + { + delete mInstance; + mInstance = 0; + } + } + + protected: + + Singleton() + { + }; + + virtual ~Singleton() + { + }; + + private: + + Singleton(const Singleton& source) + { + }; + + static T* mInstance; + }; + + template T* Singleton::mInstance = 0; + +} diff --git a/external/dtEntity/include/dtEntity/spawner.h b/external/dtEntity/include/dtEntity/spawner.h new file mode 100644 index 000000000..bd9330a05 --- /dev/null +++ b/external/dtEntity/include/dtEntity/spawner.h @@ -0,0 +1,176 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include + +namespace dtEntity +{ + class Entity; + + /** + * Spawner: a template for creating entities. + * Each spawner contains a number of components which contain properties. + * When Spawner::Spawn is called, components are created for the passed entity and + * their properties are set to specified values. + * Spawners can form a sort of inheritance tree. When a child spawner is used to + * spawn an entity, all components defined in the spawner and its parent chain are + * created. Children spawners can overwrite the property values of their parents. + */ + class DT_ENTITY_EXPORT Spawner : public osg::Referenced + { + public: + + typedef std::map ComponentProperties; + + /** + * Constructor + */ + Spawner(const std::string& name, const std::string& mapName, Spawner* parent = NULL); + + /** + *return name of spawner + */ + std::string GetName() const { return mName; } + + /** + *return name of map this spawner was loaded from + */ + std::string GetMapName() const { return mMapName; } + void SetMapName(const std::string& v) { mMapName = v; } + + /** + * Should spawner show up in spawner drag & drop GUI? + */ + bool GetAddToSpawnerStore() const { return mAddToSpawnerStore; } + void SetAddToSpawnerStore(bool v) { mAddToSpawnerStore = v; } + + /** + * category for spawner store + */ + std::string GetGUICategory() { return mGUICategory; } + void SetGUICategory(const std::string& v) { mGUICategory = v; } + + /** + * icon for representing spawner in GUI + */ + std::string GetIconPath() { return mIconPath; } + void SetIconPath(const std::string& v) { mIconPath = v; } + + /** + *return name of map this spawner was loaded from + */ + Spawner* GetParent() { return mParent; } + const Spawner* GetParent() const { return mParent; } + + /** + * Collect all components of entity and all properties of these components + * and store them + */ + void InitFromEntity(const Entity& entity); + + /** + * Add components to entity and set their properties. Calls Finished(). + */ + bool Spawn(Entity& entity) const; + + /** + * Copy value from newval to a component property + */ + bool SetValue(ComponentType ctype, StringId propname, const Property& newval); + + /** + * Return true if spawner contains a component of this type + */ + bool HasComponent(ComponentType ctype) const; + + /** + * Return true if spawner or one of its parents contain a component of this type + */ + bool HasComponentRecursive(ComponentType ctype) const; + + /** + * Add a component of type ctype. The props container holds the initial property + * values to assign to the component. + */ + void AddComponent(ComponentType ctype, const GroupProperty& props); + + /** + * Remove component of this type. Return true if component existed + */ + bool RemoveComponent(ComponentType ctype); + + /** + * Get property values to assign to component after spawning it + */ + GroupProperty GetComponentValues(ComponentType ctype) const; + + /** + * Set properties of existing component in spawner.The props container holds the initial property + * values to assign to the component. All previous component values are cleared. + */ + void SetComponentValues(ComponentType ctype, const GroupProperty&); + + /** + * Get a map of components and their properties set for this spawner + */ + void GetAllComponentProperties(ComponentProperties& props) const; + + /** + * Get component properties of spawner hierarchy, children values overwrite + * parent values + */ + void GetAllComponentPropertiesRecursive(ComponentProperties& props) const; + + protected: + + virtual ~Spawner(); + + private: + + // name of spawner + std::string mName; + + // name of map this spawner was loaded from + std::string mMapName; + + // icon for representing spawner in GUI + std::string mIconPath; + + // should spawner show up in spawner drag & drop GUI? + bool mAddToSpawnerStore; + + // category for spawner store + std::string mGUICategory; + + // parent spawner, may be empty + osg::ref_ptr mParent; + + // The components and their properties that should be spawned + ComponentProperties mComponentProperties; + }; + +} diff --git a/external/dtEntity/include/dtEntity/stringid.h b/external/dtEntity/include/dtEntity/stringid.h new file mode 100644 index 000000000..420627113 --- /dev/null +++ b/external/dtEntity/include/dtEntity/stringid.h @@ -0,0 +1,77 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include + +namespace dtEntity +{ + + // serial ID for strings + + #if DTENTITY_USE_STRINGS_AS_STRINGIDS + typedef std::string StringId; + #else + typedef unsigned int StringId; + #endif + + // type id for messages + typedef StringId MessageType; + + // type id for components + typedef StringId ComponentType; + + /** + * Get a unique StringId for given string. + * If DTENTITY_USE_STRINGS_AS_STRINGIDS macri is set to ON + * this returns the string itself. Else a CRC32 hash + * is returned. + * In any case, the crc32 value is added to a reverse lookup table + * so that it can be resolved back to a string. + * This function is thread safe. + * @param str The string to index + */ + StringId DT_ENTITY_EXPORT SID(const std::string& str); + + /** + * Get the string that was used to generate the String id. + * If DTENTITY_USE_STRINGS_AS_STRINGIDS macro is set + * the input string is returned unchanged. Else + * a crc32 value is expected as input. + */ + std::string DT_ENTITY_EXPORT GetStringFromSID(StringId id); + + /** + * get string id crc32 hash of string, don't add to reverse lookup + */ + StringId DT_ENTITY_EXPORT SIDHash(const std::string& str); + + /** + * get string id crc32 hash of string, add to reverse lookup + */ + StringId DT_ENTITY_EXPORT SID(unsigned int hash); + + unsigned int DT_ENTITY_EXPORT SIDToUInt(StringId); + +} diff --git a/external/dtEntity/include/dtEntity/systeminterface.h b/external/dtEntity/include/dtEntity/systeminterface.h new file mode 100644 index 000000000..f132d9979 --- /dev/null +++ b/external/dtEntity/include/dtEntity/systeminterface.h @@ -0,0 +1,116 @@ +#pragma once + +/* -*-c++-*- + * dtEntity Game and Simulation Engine + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library 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 Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Martin Scheffler + */ + +#include + +namespace dtEntity +{ + #if defined(_MSC_VER) + typedef __int64 Timer_t; + #else + typedef unsigned long long Timer_t; + #endif + + class SystemInterface + { + public: + + virtual ~SystemInterface() {} + + /** + * Send tick messages to main message pump, also emit + * all queued messages + */ + virtual void EmitTickMessagesAndQueuedMessages() = 0; + + /** + * Send PostUpdateMessage to main message pump + */ + virtual void EmitPostUpdateMessage() = 0; + + /** + * Get simulation time delta since last tick in seconds + */ + virtual float GetDeltaSimTime() const = 0; + + /** + * Get real time delta since last tick in seconds + */ + virtual float GetDeltaRealTime() const = 0; + + /** + * Get scaling value from real time to simulation time + */ + virtual float GetTimeScale() const = 0; + + /** + * Set scaling value from real time to simulation time. + * A value of 2 means simulation runs twice as fast as real time + * Causes a TimeChangedMessage to be sent + */ + virtual void SetTimeScale(float) = 0; + + /** + * Get number of seconds since start of simulation + */ + virtual double GetSimulationTime() const = 0; + + /** + * Set number of seconds since start of simulation + * Causes a TimeChangedMessage to be sent + */ + virtual void SetSimulationTime(double) = 0; + + + /** + * Number of microseconds since 1.1.1970 + * Causes a TimeChangedMessage to be sent + */ + virtual void SetSimulationClockTime(Timer_t) = 0; + + /** + * Get number of microseconds since 1/1/1970 + */ + virtual Timer_t GetSimulationClockTime() const = 0; + + /** + * Get current system time in number of microseconds since 1/1/1970 + */ + virtual Timer_t GetRealClockTime() = 0; + + /** + * Get absolute path from a relative file path. + * Returns empty string if file is not found + */ + virtual std::string FindDataFile(const std::string& filename) = 0; + + /** + * return true if a file exists + */ + virtual bool FileExists(const std::string& filename) = 0; + + virtual int GetArgC() = 0; + virtual const char** GetArgV() = 0; + + }; + +} diff --git a/external/dtEntity/include/dtEntity/systemmessages.h b/external/dtEntity/include/dtEntity/systemmessages.h new file mode 100644 index 000000000..8765ac26e --- /dev/null +++ b/external/dtEntity/include/dtEntity/systemmessages.h @@ -0,0 +1,994 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include + +namespace dtEntity +{ + + /** + * These messages are sent by dtEntity subsystems like map or application. User code can + * register itself to these messages and react to them. In most cases, user code should not have + * to send + * these messages. + */ + + //////////////////////////////////////////////////////////////////////////////// + class MessageFactory; + + /** + * Adds all messages to message factory + */ + void DT_ENTITY_EXPORT RegisterSystemMessages(MessageFactory&); + + //////////////////////////////////////////////////////////////////////////////// + /** + * Tick message gets sent each frame by the system. + * Register for this message if you want to continually update something. + * Messages in the message queue are posted after the tick message + */ + class DT_ENTITY_EXPORT TickMessage + : public Message + { + public: + + // type identifier of this message class + static const MessageType TYPE; + + // string identifiers for parameter names + static const StringId DeltaSimTimeId; + static const StringId DeltaRealTimeId; + static const StringId SimTimeScaleId; + static const StringId SimulationTimeId; + + // Constructor + TickMessage(); + TickMessage(MessageType t); + + // Create a copy of this message on the heap + virtual Message* Clone() const { return CloneContainer(); } + + // getters (you could do GetFloat(TickMessage::DeltaSimTimeId) instead) + float GetDeltaSimTime() const { return mDeltaSimTime.Get(); } + float GetDeltaRealTime() const { return mDeltaRealTime.Get(); } + float GetSimTimeScale() const { return mSimTimeScale.Get(); } + double GetSimulationTime() const { return mSimulationTime.Get(); } + + void SetDeltaSimTime(float v) { mDeltaSimTime.Set(v); } + void SetDeltaRealTime(float v) { mDeltaRealTime.Set(v); } + void SetSimTimeScale(float v) { mSimTimeScale.Set(v); } + void SetSimulationTime(double v) { mSimulationTime.Set(v); } + + private: + + FloatProperty mDeltaSimTime; + FloatProperty mDeltaRealTime; + FloatProperty mSimTimeScale; + DoubleProperty mSimulationTime; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * This message gets sent when a camera component is created. + */ + class DT_ENTITY_EXPORT CameraAddedMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId AboutEntityId; + static const StringId ContextIdId; + + CameraAddedMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + EntityId GetAboutEntityId() const { return mAboutEntityId.Get(); } + void SetAboutEntityId(EntityId id) { mAboutEntityId.Set(id); } + + void SetContextId(unsigned int v) { mContextId.Set(v); } + unsigned int GetContextId() const { return mContextId.Get(); } + + private: + + UIntProperty mAboutEntityId; + dtEntity::UIntProperty mContextId; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * This message gets sent when a camera component is deleted. + */ + class DT_ENTITY_EXPORT CameraRemovedMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId AboutEntityId; + CameraRemovedMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + EntityId GetAboutEntityId() const { return mAboutEntityId.Get(); } + void SetAboutEntityId(EntityId id) { mAboutEntityId.Set(id); } + + private: + + UIntProperty mAboutEntityId; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Is sent when a window is to be closed, triggered by WindowManager::CloseWindow. + * used internally to asynchronously close window + */ + class DT_ENTITY_EXPORT InternalCloseWindowMessage + : public Message + { + public: + + // type identifier of this message class + static const MessageType TYPE; + static const StringId NameId; + + InternalCloseWindowMessage(); + + // Create a copy of this message on the heap + virtual dtEntity::Message* Clone() const { return CloneContainer(); } + + void SetName(const std::string& v) { mName.Set(v); } + std::string GetName() const { return mName.Get(); } + + private: + dtEntity::StringProperty mName; + + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * EndOfFrameMessage gets sent after TickMessage and after messages in + * the message queue are emitted. + */ + class DT_ENTITY_EXPORT EndOfFrameMessage + : public TickMessage + { + public: + static const MessageType TYPE; + + EndOfFrameMessage(); + virtual Message* Clone() const { return CloneContainer(); } + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * PostUpdateMessage gets sent after scene graph update traversal + */ + class DT_ENTITY_EXPORT PostUpdateMessage + : public TickMessage + { + public: + static const MessageType TYPE; + + PostUpdateMessage(); + virtual Message* Clone() const { return CloneContainer(); } + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * This message gets sent when the method EntityManager::AddToScene method is + * called. The layer system reacts to this message by attaching the entity to the scene + * graph. + */ + class DT_ENTITY_EXPORT EntityAddedToSceneMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId AboutEntityId; + static const StringId EntityNameId; + static const StringId UniqueIdId; + static const StringId MapNameId; + static const StringId VisibleInEntityListId; + + EntityAddedToSceneMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + EntityId GetAboutEntityId() const { return mAboutEntityId.Get(); } + void SetAboutEntityId(EntityId id) { mAboutEntityId.Set(id); } + + std::string GetEntityName() const { return mEntityName.Get(); } + void SetEntityName(const std::string& v) { mEntityName.Set(v); } + + std::string GetUniqueId() const { return mUniqueId.Get(); } + void SetUniqueId(const std::string& v) { mUniqueId.Set(v); } + + std::string GetMapName() const { return mMapName.Get(); } + void SetMapName(const std::string& v) { mMapName.Set(v); } + + bool GetVisibleInEntityList() const { return mVisibleInEntityList.Get(); } + void SetVisibleInEntityList(bool v) { mVisibleInEntityList.Set(v); } + + private: + + UIntProperty mAboutEntityId; + StringProperty mEntityName; + StringProperty mUniqueId; + StringProperty mMapName; + BoolProperty mVisibleInEntityList; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Is sent when an entity was removed from the selection + */ + class DT_ENTITY_EXPORT EntityDeselectedMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId AboutEntityId; + + EntityDeselectedMessage(); + + // Create a copy of this message on the heap + virtual Message* Clone() const { return CloneContainer(); } + + void SetAboutEntityId(EntityId id) { mAboutEntity.Set(id); } + EntityId GetAboutEntityId() const { return mAboutEntity.Get(); } + + private: + + UIntProperty mAboutEntity; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Is sent when name or unique id of entity is changed + */ + class DT_ENTITY_EXPORT EntityNameUpdatedMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId AboutEntityId; + static const StringId EntityNameId; + static const StringId UniqueIdId; + + EntityNameUpdatedMessage(); + + // Create a copy of this message on the heap + virtual Message* Clone() const { return CloneContainer(); } + + void SetAboutEntityId(EntityId id) { mAboutEntity.Set(id); } + EntityId GetAboutEntityId() const { return mAboutEntity.Get(); } + + void SetEntityName(const std::string& v) { mEntityName.Set(v); } + std::string GetEntityName() const { return mEntityName.Get(); } + + void SetUniqueId(const std::string& v) { mUniqueId.Set(v); } + std::string GetUniqueId() const { return mUniqueId.Get(); } + + private: + + UIntProperty mAboutEntity; + StringProperty mEntityName; + StringProperty mUniqueId; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * This message gets sent when the method EntityManager::RemoveFromScene method is + * called. The layer system reacts to this message by removing the entity from the scene + * graph. + */ + class DT_ENTITY_EXPORT EntityRemovedFromSceneMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId AboutEntityId; + static const StringId EntityNameId; + static const StringId UniqueIdId; + static const StringId MapNameId; + static const StringId VisibleInEntityListId; + + EntityRemovedFromSceneMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + EntityId GetAboutEntityId() const { return mAboutEntityId.Get(); } + void SetAboutEntityId(EntityId id) { mAboutEntityId.Set(id); } + + std::string GetEntityName() const { return mEntityName.Get(); } + void SetEntityName(const std::string& v) { mEntityName.Set(v); } + + std::string GetUniqueId() const { return mUniqueId.Get(); } + void SetUniqueId(const std::string& v) { mUniqueId.Set(v); } + + std::string GetMapName() const { return mMapName.Get(); } + void SetMapName(const std::string& v) { mMapName.Set(v); } + + bool GetVisibleInEntityList() const { return mVisibleInEntityList.Get(); } + void SetVisibleInEntityList(bool v) { mVisibleInEntityList.Set(v); } + + private: + + UIntProperty mAboutEntityId; + StringProperty mEntityName; + StringProperty mUniqueId; + StringProperty mMapName; + BoolProperty mVisibleInEntityList; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Is sent when an entity was added to the selection + */ + class DT_ENTITY_EXPORT EntitySelectedMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId AboutEntityId; + + EntitySelectedMessage(); + + // Create a copy of this message on the heap + virtual Message* Clone() const { return CloneContainer(); } + + void SetAboutEntityId(EntityId id) { mAboutEntity.Set(id); } + EntityId GetAboutEntityId() const { return mAboutEntity.Get(); } + + private: + + UIntProperty mAboutEntity; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Is sent when an entity was added to the selection + */ + class DT_ENTITY_EXPORT EntitySpawnedMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId AboutEntityId; + static const StringId SpawnerNameId; + + EntitySpawnedMessage(); + + // Create a copy of this message on the heap + virtual Message* Clone() const { return CloneContainer(); } + + void SetAboutEntityId(EntityId id) { mAboutEntity.Set(id); } + EntityId GetAboutEntityId() const { return mAboutEntity.Get(); } + + void SetSpawnerName(const std::string& name) { mSpawnerName.Set(name); } + std::string GetSpawnerName() const { return mSpawnerName.Get(); } + + private: + + UIntProperty mAboutEntity; + StringProperty mSpawnerName; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Gets sent when an entity system is added to the entity manager. + */ + class DT_ENTITY_EXPORT EntitySystemAddedMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId ComponentTypeId; + static const StringId ComponentTypeStringId; + + EntitySystemAddedMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + StringId GetComponentType() const { return mComponentType.Get(); } + void SetComponentType(StringId v) { mComponentType.Set(v); } + + std::string GetComponentTypeString() const { return mComponentTypeString.Get(); } + void SetComponentTypeString(const std::string& v) { mComponentTypeString.Set(v); } + + private: + + StringIdProperty mComponentType; + StringProperty mComponentTypeString; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Gets sent when an entity system is removed from the entity manager. + */ + class DT_ENTITY_EXPORT EntitySystemRemovedMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId ComponentTypeId; + static const StringId ComponentTypeStringId; + + EntitySystemRemovedMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + StringId GetComponentType() const { return mComponentType.Get(); } + void SetComponentType(StringId v) { mComponentType.Set(v); } + + std::string GetComponentTypeString() const { return mComponentTypeString.Get(); } + void SetComponentTypeString(const std::string& v) { mComponentTypeString.Set(v); } + + private: + + StringIdProperty mComponentType; + StringProperty mComponentTypeString; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Is sent when name or unique id of entity is changed + */ + class DT_ENTITY_EXPORT EntityVelocityNotNullMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId AboutEntityId; + static const StringId IsNullId; + + EntityVelocityNotNullMessage(); + + // Create a copy of this message on the heap + virtual Message* Clone() const { return CloneContainer(); } + + void SetAboutEntityId(EntityId id) { mAboutEntity.Set(id); } + EntityId GetAboutEntityId() const { return mAboutEntity.Get(); } + + void SetIsNull(bool v) { mIsNull.Set(v); } + bool GetIsNull() const { return mIsNull.Get(); } + + private: + + UIntProperty mAboutEntity; + BoolProperty mIsNull; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Gets sent before a map is loaded + */ + class DT_ENTITY_EXPORT MapBeginLoadMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId MapPathId; + static const StringId DataPathId; + static const StringId SaveOrderId; + + MapBeginLoadMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + std::string GetMapPath() const { return mMapPath.Get(); } + void SetMapPath(const std::string& v){ mMapPath.Set(v); } + + std::string GetDataPath() const { return mDataPath.Get(); } + void SetDataPath(const std::string& v){ mDataPath.Set(v); } + + unsigned int GetSaveOrder() const { return mSaveOrder.Get(); } + void SetSaveOrder(unsigned int v){ mSaveOrder.Set(v); } + + private: + + StringProperty mMapPath; + StringProperty mDataPath; + UIntProperty mSaveOrder; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Gets sent when a map is about to be unloaded + */ + class DT_ENTITY_EXPORT MapBeginUnloadMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId MapPathId; + + MapBeginUnloadMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + std::string GetMapPath() const { return mMapPath.Get(); } + void SetMapPath(const std::string& v){ mMapPath.Set(v); } + + private: + + StringProperty mMapPath; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Gets sent when a map was loaded + */ + class DT_ENTITY_EXPORT MapLoadedMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId MapPathId; + static const StringId DataPathId; + static const StringId SaveOrderId; + + MapLoadedMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + std::string GetMapPath() const { return mMapPath.Get(); } + void SetMapPath(const std::string& v){ mMapPath.Set(v); } + + std::string GetDataPath() const { return mDataPath.Get(); } + void SetDataPath(const std::string& v){ mDataPath.Set(v); } + + unsigned int GetSaveOrder() const { return mSaveOrder.Get(); } + void SetSaveOrder(unsigned int v){ mSaveOrder.Set(v); } + + private: + + StringProperty mMapPath; + StringProperty mDataPath; + UIntProperty mSaveOrder; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Gets sent when a map was unloaded + */ + class DT_ENTITY_EXPORT MapUnloadedMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId MapPathId; + + MapUnloadedMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + std::string GetMapPath() const { return mMapPath.Get(); } + void SetMapPath(const std::string& v){ mMapPath.Set(v); } + + private: + + StringProperty mMapPath; + }; + + //////////////////////////////////////////////////////////////////////////////// + + /** + * Emitted when mesh of an entity is changed. + */ + class DT_ENTITY_EXPORT MeshChangedMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId AboutEntityId; + static const StringId FilePathId; + + MeshChangedMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + EntityId GetAboutEntityId() const { return mAboutEntityId.Get(); } + void SetAboutEntityId(EntityId id) { mAboutEntityId.Set(id); } + + std::string GetFilePath() const { return mFilePath.Get(); } + void SetFilePath(const std::string& id) { mFilePath.Set(id); } + + private: + + UIntProperty mAboutEntityId; + StringProperty mFilePath; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Is sent when a watched resource was changed on disk + */ + class DT_ENTITY_EXPORT ResourceChangedMessage + : public Message + { + public: + + // type identifier of this message class + static const MessageType TYPE; + static const StringId PathId; + + ResourceChangedMessage(); + + // Create a copy of this message on the heap + virtual dtEntity::Message* Clone() const { return CloneContainer(); } + + void SetPath(const std::string& v) { mPath.Set(v); } + std::string GetPath() const { return mPath.Get(); } + + private: + dtEntity::StringProperty mPath; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Is sent when a watched resource was changed on disk + */ + class DT_ENTITY_EXPORT ResourceLoadedMessage + : public Message + { + public: + + // type identifier of this message class + static const MessageType TYPE; + static const StringId PathId; + + ResourceLoadedMessage(); + + // Create a copy of this message on the heap + virtual dtEntity::Message* Clone() const { return CloneContainer(); } + + void SetPath(const std::string& v) { mPath.Set(v); } + std::string GetPath() const { return mPath.Get(); } + + private: + dtEntity::StringProperty mPath; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Gets sent when a scene was loaded + */ + class DT_ENTITY_EXPORT SceneLoadedMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId SceneNameId; + + SceneLoadedMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + std::string GetSceneName() const { return mSceneName.Get(); } + void SetSceneName(const std::string& v){ mSceneName.Set(v); } + + private: + + StringProperty mSceneName; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Gets sent when a scene was unloaded + */ + class DT_ENTITY_EXPORT SceneUnloadedMessage + : public Message + { + public: + + static const MessageType TYPE; + SceneUnloadedMessage(); + virtual Message* Clone() const { return CloneContainer(); } + + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Gets sent when a spawner was added to the map system + */ + class DT_ENTITY_EXPORT SpawnerAddedMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId MapNameId; + static const StringId NameId; + static const StringId ParentNameId; + + SpawnerAddedMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + std::string GetMapName() const { return mMapName.Get(); } + void SetMapName(const std::string& v){ mMapName.Set(v); } + + std::string GetName() const { return mName.Get(); } + void SetName(const std::string& v){ mName.Set(v); } + + std::string GetParentName() const { return mParentName.Get(); } + void SetParentName(const std::string& v){ mParentName.Set(v); } + + private: + + StringProperty mName; + StringProperty mParentName; + StringProperty mMapName; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Gets sent when a spawner was modified + */ + class DT_ENTITY_EXPORT SpawnerModifiedMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId OldCategoryId; + static const StringId NewCategoryId; + static const StringId NameId; + static const StringId MapNameId; + + SpawnerModifiedMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + std::string GetName() const { return mName.Get(); } + void SetName(const std::string& v){ mName.Set(v); } + + std::string GetMapName() const { return mMapName.Get(); } + void SetMapName(const std::string& v){ mMapName.Set(v); } + + std::string GetOldCategory() const { return mOldCategory.Get(); } + void SetOldCategory(const std::string& v){ mOldCategory.Set(v); } + + std::string GetNewCategory() const { return mNewCategory.Get(); } + void SetNewCategory(const std::string& v){ mNewCategory.Set(v); } + + private: + + StringProperty mName; + StringProperty mMapName; + StringProperty mOldCategory; + StringProperty mNewCategory; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Gets sent when a spawner was removed from the map system + */ + class DT_ENTITY_EXPORT SpawnerRemovedMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId MapNameId; + static const StringId NameId; + static const StringId CategoryId; + + SpawnerRemovedMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + std::string GetMapName() const { return mMapName.Get(); } + void SetMapName(const std::string& v){ mMapName.Set(v); } + + std::string GetName() const { return mName.Get(); } + void SetName(const std::string& v){ mName.Set(v); } + + std::string GetCategory() const { return mCategory.Get(); } + void SetCategory(const std::string& v){ mCategory.Set(v); } + + private: + + StringProperty mName; + StringProperty mMapName; + StringProperty mCategory; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Is sent when entering simulation loop + */ + class DT_ENTITY_EXPORT StartSystemMessage + : public Message + { + public: + + static const MessageType TYPE; + + StartSystemMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Is sent when entering simulation loop + */ + class DT_ENTITY_EXPORT StopSystemMessage + : public Message + { + public: + + static const MessageType TYPE; + + StopSystemMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Is sent when the EntityManager::ChangeTimeSettings method is called. + */ + class DT_ENTITY_EXPORT TimeChangedMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId SimulationTimeId; + static const StringId SimulationClockTimeId; + static const StringId TimeScaleId; + + TimeChangedMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + float GetTimeScale() const { return mTimeScale.Get(); } + void SetTimeScale(float v) { mTimeScale.Set(v); } + + osg::Timer_t GetSimulationClockTime() const { return mSimulationClockTime; } + void SetSimulationClockTime(osg::Timer_t v) { mSimulationClockTime = v; } + + double GetSimulationTime() const { return mSimulationTime.Get(); } + void SetSimulationTime(double v) { mSimulationTime.Set(v); } + + private: + + DoubleProperty mSimulationTime; + osg::Timer_t mSimulationClockTime; + FloatProperty mTimeScale; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Emitted when entity is shown/hidden + */ + class DT_ENTITY_EXPORT VisibilityChangedMessage + : public Message + { + public: + + static const MessageType TYPE; + static const StringId AboutEntityId; + static const StringId VisibleId; + + VisibilityChangedMessage(); + + virtual Message* Clone() const { return CloneContainer(); } + + EntityId GetAboutEntityId() const { return mAboutEntityId.Get(); } + void SetAboutEntityId(EntityId id) { mAboutEntityId.Set(id); } + + bool GetVisible() const { return mVisible.Get(); } + void SetVisible(bool v) { mVisible.Set(v); } + + private: + + UIntProperty mAboutEntityId; + BoolProperty mVisible; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Is sent when a window was opened with WindowManager::OpenWindow + */ + class DT_ENTITY_EXPORT WindowCreatedMessage + : public Message + { + public: + + // type identifier of this message class + static const MessageType TYPE; + static const StringId NameId; + static const StringId ContextIdId; + static const StringId CameraEntityIdId; + + WindowCreatedMessage(); + + // Create a copy of this message on the heap + virtual dtEntity::Message* Clone() const { return CloneContainer(); } + + void SetName(const std::string& v) { mName.Set(v); } + std::string GetName() const { return mName.Get(); } + + void SetContextId(unsigned int v) { mContextId.Set(v); } + unsigned int GetContextId() const { return mContextId.Get(); } + + void SetCameraEntityId(unsigned int v) { mCameraEntityId.Set(v); } + unsigned int GetCameraEntityId() const { return mCameraEntityId.Get(); } + + private: + dtEntity::StringProperty mName; + dtEntity::UIntProperty mContextId; + dtEntity::UIntProperty mCameraEntityId; + }; + + //////////////////////////////////////////////////////////////////////////////// + /** + * Is sent when a window was closed + */ + class DT_ENTITY_EXPORT WindowClosedMessage + : public Message + { + public: + + // type identifier of this message class + static const MessageType TYPE; + static const StringId NameId; + + WindowClosedMessage(); + + // Create a copy of this message on the heap + virtual dtEntity::Message* Clone() const { return CloneContainer(); } + + void SetName(const std::string& v) { mName.Set(v); } + std::string GetName() const { return mName.Get(); } + + private: + dtEntity::StringProperty mName; + }; + +} diff --git a/external/dtEntity/include/dtEntity/threadsafequeue.h b/external/dtEntity/include/dtEntity/threadsafequeue.h new file mode 100644 index 000000000..97655887b --- /dev/null +++ b/external/dtEntity/include/dtEntity/threadsafequeue.h @@ -0,0 +1,82 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include + +namespace dtEntity +{ + /** + * A queue with thread safe push and pop methods + */ + template + class ThreadSafeQueue + { + public: + + void Push(T t); + bool Empty(); + T Pop(); + unsigned int GetSize(); + + private: + + OpenThreads::Mutex mQueueMutex; + std::queue mQueue; + }; + + + ////////////////////////////////////////// + + + template + void ThreadSafeQueue::Push(T t) + { + OpenThreads::ScopedLock lock(mQueueMutex); + mQueue.push(t); + } + + template + bool ThreadSafeQueue::Empty() + { + OpenThreads::ScopedLock lock(mQueueMutex); + return mQueue.empty(); + } + + template + T ThreadSafeQueue::Pop() + { + OpenThreads::ScopedLock lock(mQueueMutex); + if(mQueue.empty()) return T(); + T t = mQueue.front(); + mQueue.pop(); + return t; + } + + template + unsigned int ThreadSafeQueue::GetSize() + { + OpenThreads::ScopedLock lock(mQueueMutex); + return mQueue.size(); + } +} diff --git a/external/dtEntity/include/dtEntity/uniqueid.h b/external/dtEntity/include/dtEntity/uniqueid.h new file mode 100644 index 000000000..583b3aa2b --- /dev/null +++ b/external/dtEntity/include/dtEntity/uniqueid.h @@ -0,0 +1,30 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include + +#include + +namespace dtEntity +{ + std::string DT_ENTITY_EXPORT CreateUniqueIdString(); +} diff --git a/external/dtEntity/include/dtEntity/windowinterface.h b/external/dtEntity/include/dtEntity/windowinterface.h new file mode 100644 index 000000000..ec0c5b6b0 --- /dev/null +++ b/external/dtEntity/include/dtEntity/windowinterface.h @@ -0,0 +1,124 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include + +namespace dtEntity +{ + //////////////////////////////////////////////////////////////////////////////// + class WindowInterface + { + public: + + virtual ~WindowInterface() {} + + /** + * Opens a new window if used viewer is a composite viewer. + * @param name Name of osg nodes for window, view and camera to set + * @param traits OSG GraphicsWindow traits to use + * @contexId will receive context id of newly created context + * @return true if success + */ + virtual bool OpenWindow(const std::string& name, unsigned int& contextId) = 0; + + virtual void CloseWindow(unsigned int contextid) = 0; + + /** + * Get pick ray at given screen position + * @param usePixels if true, use x-y screen coordinates, if false use values from -1 to 1 + */ + virtual Vec3f GetPickRay(unsigned int contextid, float x, float y, bool usePixels = false) const = 0; + + /** + Get window size and position of window with given context id + */ + virtual bool GetWindowGeometry(unsigned int contextid, int& x, int& y, int& width, int& height) const = 0; + + /** + Set window size and position of window with given context id + */ + virtual bool SetWindowGeometry(unsigned int contextid, int x, int y, int width, int height) = 0; + + /** + Should window be displayed at full screen size? + */ + virtual void SetFullscreen(unsigned int contextid, bool fullscreen) = 0; + virtual bool GetFullscreen(unsigned int contextid) const = 0; + + /** + * Return entity id of first intersected entity. + */ + virtual EntityId PickEntity(double x, double y, unsigned int nodemask, + unsigned int contextid, bool usePixels = true) const = 0; + + /** + * Show or hide cursor when it is above this window? + */ + virtual void SetShowCursor(unsigned int contextid, bool) = 0; + + /** + * project world space point into screen coordinates + */ + virtual Vec3d ConvertWorldToScreenCoords(unsigned int contextid, const Vec3d& coord) = 0; + + /** + * Should the window with given context id be continuously redrawn + * or only by request? Default is on + */ + virtual void SetContinuousRedraw(unsigned int contextid, bool) = 0; + + /** + * If Continuous Redraw is off, request a redraw in next render traversal + */ + virtual void RequestRedraw(unsigned int contextid) = 0; + + /** + * Holds intersection info + */ + struct Intersection + { + Vec3d mPosition; + Vec3f mNormal; + EntityId mEntityId; + }; + + typedef std::vector Intersections; + + /** + * Get intersections between start and end and add them to isects vector + * @param start Start of intersection line + * @param end End of intersection lnie + * @param isects Vector return value for isect results + * @param nodemask Bit mask, used for selecting nodes for intersection + * @param layer Name of layer attach point component from which intersecition test will + * be executed downwards (default: layer "default") + * @return true if an intersection was found + */ + virtual bool GetIntersections(const Vec3d& start, const Vec3d& end, + std::vector& isects, + unsigned int nodemask = NodeMasks::PICKABLE | NodeMasks::TERRAIN, + dtEntity::StringId layer = dtEntity::StringId() + ) const = 0; + + }; + +} diff --git a/external/dtEntity/include/dtEntityOSG/cameracomponent.h b/external/dtEntity/include/dtEntityOSG/cameracomponent.h new file mode 100644 index 000000000..e1e750569 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/cameracomponent.h @@ -0,0 +1,255 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include + +namespace osg +{ + class Group; + class Camera; +} + +namespace dtEntityOSG +{ + /** + * The camera component holds properties for the osg::Camera object + */ + class DTENTITY_OSG_EXPORT CameraComponent + : public TransformComponent + { + + typedef TransformComponent BaseClass; + + public: + + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId ContextIdId; + static const dtEntity::StringId LayerAttachPointId; + + static const dtEntity::StringId CullingModeId; + static const dtEntity::StringId CullMaskId; + static const dtEntity::StringId NoAutoNearFarCullingId; + static const dtEntity::StringId BoundingVolumeNearFarCullingId; + static const dtEntity::StringId PrimitiveNearFarCullingId; + static const dtEntity::StringId FieldOfViewId; + static const dtEntity::StringId AspectRatioId; + static const dtEntity::StringId NearClipId; + static const dtEntity::StringId FarClipId; + static const dtEntity::StringId LODScaleId; + static const dtEntity::StringId ClearColorId; + static const dtEntity::StringId PositionId; + static const dtEntity::StringId EyeDirectionId; + static const dtEntity::StringId UpId; + + static const dtEntity::StringId OrthoLeftId; + static const dtEntity::StringId OrthoRightId; + static const dtEntity::StringId OrthoTopId; + static const dtEntity::StringId OrthoBottomId; + static const dtEntity::StringId OrthoZNearId; + static const dtEntity::StringId OrthoZFarId; + + static const dtEntity::StringId ProjectionModeId; + static const dtEntity::StringId ModePerspectiveId; + static const dtEntity::StringId ModeOrthoId; + + CameraComponent(); + + virtual ~CameraComponent(); + + virtual dtEntity::ComponentType GetType() const + { + return TYPE; + } + + virtual void OnAddedToEntity(dtEntity::Entity& entity); + virtual void OnRemovedFromEntity(dtEntity::Entity& entity); + + osg::Camera* GetCamera() const; + + virtual void Finished(); + + void FetchCamera(); + + void SetContextId(int id); + int GetContextId() const { return mContextIdVal; } + + void SetLayerAttachPoint(dtEntity::StringId id); + dtEntity::StringId GetLayerAttachPoint() const; + + void SetProjectionMode(dtEntity::StringId); + dtEntity::StringId GetProjectionMode() const { return mProjectionModeVal; } + + void SetCullingMode(dtEntity::StringId); + dtEntity::StringId GetCullingMode() const { return mCullingModeVal; } + + /** Set up vector of camera. Call UpdateViewMatrix to apply changes. */ + void SetUp(const osg::Vec3d&); + osg::Vec3d GetUp() const; + + /** Set eye position of camera. Call UpdateViewMatrix to apply changes. */ + void SetPosition(const osg::Vec3d&); + osg::Vec3d GetPosition() const; + + /** Set look direction of camera. Should be a normalized vector! + * Call UpdateViewMatrix to apply changes. + */ + void SetEyeDirection(const osg::Vec3d&); + osg::Vec3d GetEyeDirection() const; + + /** + * Re-calculate osg camera view matrix from up, pos and eye dir vectors + */ + void UpdateViewMatrix(); + + /** + * Re-calculate osg camera projection matrix from mode, near, far etc + */ + void UpdateProjectionMatrix(); + + /** + * Set the osg node mask controlling which nodes are + * visible to the camera. Please see dtEntity/nodemasks.h + */ + void SetCullMask(unsigned int mask); + unsigned int GetCullMask() const; + + void SetClearColor(const osg::Vec4&); + osg::Vec4 GetClearColor() const; + + virtual osg::Vec3d GetTranslation() const { return GetPosition(); } + virtual void SetTranslation(const osg::Vec3d& v) { SetPosition(v); } + + virtual osg::Quat GetRotation() const + { + osg::Quat q; + q.makeRotate(osg::Vec3d(0,1,0), mEyeDirection.Get()); + return q; + } + + virtual void SetRotation(const osg::Quat& q) + { + mEyeDirection.Set(q * osg::Vec3d(0, 1, 0)); + } + + void SetFieldOfView(double v); + double GetFieldOfView() const; + + void SetAspectRatio(double v); + double GetAspectRatio() const; + + void SetNearClip(double v); + double GetNearClip() const; + + void SetFarClip(double v); + double GetFarClip() const; + + void SetLODScale(float v); + float GetLODScale() const; + + void SetOrthoLeft(double v); + double GetOrthoLeft() const; + + void SetOrthoRight(double v); + double GetOrthoRight() const; + + void SetOrthoTop(double v); + double GetOrthoTop() const; + + void SetOrthoBottom(double v); + double GetOrthoBottom() const; + + void SetOrthoZNear(double v); + double GetOrthoZNear() const; + + void SetOrthoZFar(double v); + double GetOrthoZFar() const; + + void TryAssignContext(); + + private: + + + + dtEntity::DynamicIntProperty mContextId; + int mContextIdVal; + dtEntity::DynamicStringIdProperty mLayerAttachPoint; + dtEntity::StringId mLayerAttachPointVal; + + dtEntity::DynamicStringIdProperty mCullingMode; + dtEntity::StringId mCullingModeVal; + dtEntity::DynamicDoubleProperty mFieldOfView; + double mFieldOfViewVal; + dtEntity::DynamicDoubleProperty mAspectRatio; + double mAspectRatioVal; + dtEntity::DynamicDoubleProperty mNearClip; + double mNearClipVal; + dtEntity::DynamicDoubleProperty mFarClip; + double mFarClipVal; + dtEntity::DynamicVec4Property mClearColor; + dtEntity::DynamicFloatProperty mLODScale; + dtEntity::Vec3dProperty mPosition; + dtEntity::Vec3dProperty mUp; + dtEntity::Vec3dProperty mEyeDirection; + dtEntity::DynamicUIntProperty mCullMask; + dtEntity::DynamicStringIdProperty mProjectionMode; + dtEntity::StringId mProjectionModeVal; + + dtEntity::DynamicDoubleProperty mOrthoLeft; + dtEntity::DynamicDoubleProperty mOrthoRight; + dtEntity::DynamicDoubleProperty mOrthoBottom; + dtEntity::DynamicDoubleProperty mOrthoTop; + dtEntity::DynamicDoubleProperty mOrthoZNear; + dtEntity::DynamicDoubleProperty mOrthoZFar; + double mOrthoLeftVal; + double mOrthoRightVal; + double mOrthoBottomVal; + double mOrthoTopVal; + double mOrthoZNearVal; + double mOrthoZFarVal; + + }; + + + //////////////////////////////////////////////////////////////////////////////// + + class DTENTITY_OSG_EXPORT CameraSystem + : public dtEntity::DefaultEntitySystem + { + public: + + static const dtEntity::ComponentType TYPE; + + CameraSystem(dtEntity::EntityManager& em); + ~CameraSystem(); + + dtEntity::EntityId GetCameraEntityByContextId(int id); + + void OnWindowCreated(const dtEntity::Message& msg); + + private: + dtEntity::MessageFunctor mWindowCreatedFunctor; + + }; +} diff --git a/external/dtEntity/include/dtEntityOSG/componentfactories.h b/external/dtEntity/include/dtEntityOSG/componentfactories.h new file mode 100644 index 000000000..352552ae0 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/componentfactories.h @@ -0,0 +1,34 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include + +namespace dtEntity +{ + class ComponentPluginManager; +} + +namespace dtEntityOSG +{ + + void DTENTITY_OSG_EXPORT RegisterStandardFactories(dtEntity::ComponentPluginManager& pluginManager); +} diff --git a/external/dtEntity/include/dtEntityOSG/dtentityosg_config.h b/external/dtEntity/include/dtEntityOSG/dtentityosg_config.h new file mode 100644 index 000000000..ae328742f --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/dtentityosg_config.h @@ -0,0 +1,6 @@ +#pragma once + +// auto-generated by CMake, do not edit! + +// was osgEphemeris found by cmake? +#define OSGEPHEMERIS_FOUND 0 diff --git a/external/dtEntity/include/dtEntityOSG/export.h b/external/dtEntity/include/dtEntityOSG/export.h new file mode 100644 index 000000000..c5107d3b4 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/export.h @@ -0,0 +1,31 @@ +#pragma once + +/* +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) +# ifdef DTENTITY_OSG_LIBRARY +# define DTENTITY_OSG_EXPORT __declspec(dllexport) +# else +# define DTENTITY_OSG_EXPORT __declspec(dllimport) +# endif +#else +# define DTENTITY_OSG_EXPORT +#endif diff --git a/external/dtEntity/include/dtEntityOSG/groundclampingcomponent.h b/external/dtEntity/include/dtEntityOSG/groundclampingcomponent.h new file mode 100644 index 000000000..6df095300 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/groundclampingcomponent.h @@ -0,0 +1,186 @@ +#pragma once + +/* +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace dtEntity +{ + class MapSystem; +} + +namespace dtEntityOSG +{ + + class GroundClampingComponent : public dtEntity::Component + { + typedef dtEntity::Component BaseClass; + + public: + + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId ClampingModeId; + static const dtEntity::StringId ClampingMode_DisabledId; + static const dtEntity::StringId ClampingMode_KeepAboveTerrainId; + static const dtEntity::StringId ClampingMode_SetHeightToTerrainHeightId; + static const dtEntity::StringId ClampingMode_SetHeightAndRotationToTerrainId; + static const dtEntity::StringId MinDistToCameraId; + static const dtEntity::StringId MinMovementDeltaId; + static const dtEntity::StringId VerticalOffsetId; + + GroundClampingComponent(); + virtual ~GroundClampingComponent(); + + virtual dtEntity::ComponentType GetType() const { return TYPE; } + virtual bool IsInstanceOf(dtEntity::ComponentType id) const + { + return (id == TYPE); + } + + virtual void OnAddedToEntity(dtEntity::Entity& e); + virtual void Finished(); + dtEntityOSG::TransformComponent* GetTransformComponent() const { return mTransformComponent; } + + void SetClampingMode(dtEntity::StringId mode) { mClampingMode.Set(mode); } + dtEntity::StringId GetClampingMode() const { return mClampingMode.Get(); } + + float GetVerticalOffset() const { return mVerticalOffset.Get(); } + void SetVerticalOffset(float v) { mVerticalOffset.Set(v); } + + // for keeping track of intersections when using osgSim HeightAboveTerrain + void SetIntersectIndex(unsigned int i) { mIntersectIndex = i; } + unsigned int GetIntersectIndex() const { return mIntersectIndex; } + + osgUtil::LineSegmentIntersector* GetIntersector() const { return mIntersector.get(); } + void SetIntersector(osgUtil::LineSegmentIntersector* isect) { mIntersector = isect; } + + void SetLastClampedPosition(const osg::Vec3d& p) { mLastClampedPosition = p; } + osg::Vec3d GetLastClampedPosition() const { return mLastClampedPosition; } + + void SetLastClampedAttitude(const osg::Quat& p) { mLastClampedAttitude = p; } + osg::Quat GetLastClampedAttitude() const { return mLastClampedAttitude; } + + void SetLastClampedNormal(const osg::Vec3& p) { mLastClampedNormal = p; } + osg::Vec3 GetLastClampedNormal() const { return mLastClampedNormal; } + + void SetMinDistToCamera(float p) { mMinDistToCamera.Set(p); } + float GetMinDistToCamera() const { return mMinDistToCamera.Get(); } + + void SetMinMovementDelta(float p) { mMinMovementDelta.Set(p); } + float GetMinMovementDelta() const { return mMinMovementDelta.Get(); } + + void SetDirty(bool v) { mDirty = v; } + bool GetDirty() const { return mDirty; } + + private: + + dtEntity::StringIdProperty mClampingMode; + dtEntity::FloatProperty mVerticalOffset; + dtEntity::FloatProperty mMinDistToCamera; + dtEntity::FloatProperty mMinMovementDelta; + + dtEntityOSG::TransformComponent* mTransformComponent; + unsigned int mIntersectIndex; + dtEntity::Entity* mEntity; + osg::ref_ptr mIntersector; + osg::Vec3d mLastClampedPosition; + osg::Vec3d mLastClampedNormal; + + bool mDirty; + osg::Quat mLastClampedAttitude; + + }; + + + //////////////////////////////////////////////////////////////////////////////// + + + class GroundClampingSystem + : public dtEntity::DefaultEntitySystem + , public dtEntity::ScriptAccessor + { + typedef dtEntity::DefaultEntitySystem BaseClass; + + public: + + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId EnabledId; + static const dtEntity::StringId IntersectLayerId; + static const dtEntity::StringId FetchLODsId; + + GroundClampingSystem(dtEntity::EntityManager& em); + ~GroundClampingSystem(); + + void OnRemoveFromEntityManager(dtEntity::EntityManager& em); + + void Tick(const dtEntity::Message& msg); + void CameraAdded(const dtEntity::Message& msg); + void CameraRemoved(const dtEntity::Message& msg); + void MapLoaded(const dtEntity::Message& msg); + + bool ClampToTerrain(osg::Vec3d& position, int voffset = 10000, unsigned int nodemask = dtEntity::NodeMasks::TERRAIN); + + void SetIntersectLayer(dtEntity::StringId); + dtEntity::StringId GetIntersectLayer() const; + + + virtual bool StorePropertiesToScene() const { return true; } + + void SetEnabled(bool v); + bool GetEnabled() const; + private: + + dtEntity::Property* ScriptGetTerrainHeight(const dtEntity::PropertyArgs& args); + + dtEntityOSG::TransformComponent* GetTransformComp(dtEntity::EntityId eid, GroundClampingComponent* component); + void DirtyAll(); + void HandleIntersection(GroundClampingComponent* component, + const osgUtil::LineSegmentIntersector::Intersection& intersection, float dt, double simTime); + + dtEntity::MessageFunctor mTickFunctor; + dtEntity::MessageFunctor mCameraAddedFunctor; + dtEntity::MessageFunctor mCameraRemovedFunctor; + dtEntity::MessageFunctor mMapLoadedFunctor; + osgUtil::IntersectionVisitor mIntersectionVisitor; + osg::observer_ptr mRootNode; + osg::ref_ptr mIntersectorGroup; + + dtEntity::DynamicBoolProperty mEnabled; + bool mEnabledVal; + dtEntity::DynamicStringIdProperty mIntersectLayer; + dtEntity::StringId mIntersectLayerVal; + dtEntity::BoolProperty mFetchLODs; + + osgSim::LineOfSight mLos; + dtEntityOSG::CameraComponent* mCamera; + + }; +} diff --git a/external/dtEntity/include/dtEntityOSG/groupcomponent.h b/external/dtEntity/include/dtEntityOSG/groupcomponent.h new file mode 100644 index 000000000..0c7f253b6 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/groupcomponent.h @@ -0,0 +1,105 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include + +namespace osg +{ + class Group; +} + +namespace dtEntityOSG +{ + /** + * Holds a single OSG group. + */ + class DTENTITY_OSG_EXPORT GroupComponent : public NodeComponent + { + public: + + typedef NodeComponent BaseClass; + + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId ChildrenId; + + /** + * CTor, creates a new group component + */ + GroupComponent(); + + /** + * CTor, uses passed group component + */ + GroupComponent(osg::Group* group); + + virtual ~GroupComponent(); + + virtual dtEntity::ComponentType GetType() const + { + return TYPE; + } + + virtual osg::Group* GetGroup() const; + + // return group to attach children to + virtual osg::Group* GetAttachmentGroup() const { return GetGroup(); } + + bool AddChildComponent(dtEntity::ComponentType c); + bool RemoveChildComponent(dtEntity::ComponentType c); + + /** + * Expects an array of stringid properties containing component types + * of children. These will be attached. + */ + void SetChildren(const dtEntity::PropertyArray& arr); + dtEntity::PropertyArray GetChildren() const { return mChildrenVal.Get(); } + + private: + + // to prevent redundant code in constructors + void Init(); + + dtEntity::DynamicArrayProperty mChildren; + dtEntity::ArrayProperty mChildrenVal; + }; + + + /////////////////////////////////////////////////////////////////////////// + // storage only + class DTENTITY_OSG_EXPORT GroupSystem + : public dtEntity::DefaultEntitySystem + { + public: + GroupSystem(dtEntity::EntityManager& em) + : dtEntity::DefaultEntitySystem(em, NodeComponent::TYPE) + { + + } + }; + + +} diff --git a/external/dtEntity/include/dtEntityOSG/initosgviewer.h b/external/dtEntity/include/dtEntityOSG/initosgviewer.h new file mode 100644 index 000000000..9671079ce --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/initosgviewer.h @@ -0,0 +1,78 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include + +namespace osg +{ + class Group; +} + +namespace osgViewer +{ + class ViewerBase; +} + +namespace dtEntity +{ + class EntityManager; +} + +namespace dtEntityOSG +{ + + /** + * Convenience setup function for dtEntity. + * If you want to do fancy stuff in your setup then maybe you should not call this, instead write your own! + * + * Installs a log handler, calls SetupDataPaths(), calls InitDtEntity(), calls SetupViewer(), then calls DoScreenSetup() + * @param argc number of command line args + * @param standard c command line args + * @param viewer An instance of either osgViewer::Viewer or osgViewer::CompositeViewer + * @param em a valid entity manager + * @param addStatsHandler Should osg stats handler be installed (activated with key insert) + * @param checkPaths Should SetupDataPaths complain about missing paths + * @param addConsoleLog Should log messages be output to console + * @param pSceneNode An osg group that is used as scene graph root node. This is added as scene node to the main scene, also + * the main update callback that drives dtEntity is installed to this node. If this is NULL, a new osg::Group is created + */ + bool DTENTITY_OSG_EXPORT InitOSGViewer(int argc, char** argv, + osgViewer::ViewerBase& viewer, dtEntity::EntityManager& em, + bool addStatsHandler = true, bool checkPaths = true, bool addConsoleLog = true, osg::Group* pSceneNode = 0); + + + /** + * Sets scene graph root node and adds callbacks + * @param viewer An instance of either osgViewer::Viewer or osgViewer::CompositeViewer + * @param pSceneNode An osg group that is used as scene graph root node. This is added as scene node to the main scene, also + * the main update callback that drives dtEntity is installed to this node. + */ + void DTENTITY_OSG_EXPORT SetupSceneGraph(osgViewer::ViewerBase& viewer, dtEntity::EntityManager& em, osg::Group* pSceneNode); + + + /** + * analyze command line and open OSG window with correct traits + * @return true if success + */ + bool DTENTITY_OSG_EXPORT DoScreenSetup(int argc, char** argv, osgViewer::ViewerBase& viewer, dtEntity::EntityManager& em); +} diff --git a/external/dtEntity/include/dtEntityOSG/layerattachpointcomponent.h b/external/dtEntity/include/dtEntityOSG/layerattachpointcomponent.h new file mode 100644 index 000000000..c43724e49 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/layerattachpointcomponent.h @@ -0,0 +1,128 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include +#include + +namespace dtEntityOSG +{ + + class DTENTITY_OSG_EXPORT LayerAttachPointComponent + : public GroupComponent + { + typedef GroupComponent BaseClass; + + public: + + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId NameId; + + LayerAttachPointComponent(); + virtual ~LayerAttachPointComponent(); + virtual void Finished(); + void OnAddedToEntity(dtEntity::Entity& entity); + void OnRemovedFromEntity(dtEntity::Entity& entity); + + /** + * Set osg group node that will hold layer component nodes + * as children. When this is set, all layer components are + * traversed and their nodes are attached to this group node + * if the layer name fits + */ + virtual void SetNode(osg::Group* node); + + + /** + * Get name SID identifying this layer attach point + */ + dtEntity::StringId GetName() const { return mName.Get(); } + + /** + * Set name SID identifying this layer attach point. + * When the name is changed all layer components are + * traversed and their nodes are attached to this group node + * if the layer name fits + */ + void SetName(dtEntity::StringId name); + + virtual dtEntity::ComponentType GetType() const + { + return TYPE; + } + + private: + dtEntity::EntityManager* mEntityManager; + dtEntity::StringIdProperty mName; + dtEntity::StringId mCurrentName; + }; + + + //////////////////////////////////////////////////////////////////////////////// + + class DTENTITY_OSG_EXPORT LayerAttachPointSystem + : public dtEntity::DefaultEntitySystem + , public dtEntity::ScriptAccessor + { + friend class LayerAttachPointComponent; + + typedef dtEntity::DefaultEntitySystem BaseClass; + + public: + + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId DefaultLayerId; + static const dtEntity::StringId RootId; + + LayerAttachPointSystem(dtEntity::EntityManager& em); + + virtual bool DeleteComponent(dtEntity::EntityId eid); + + bool GetByName(dtEntity::StringId name, LayerAttachPointComponent*& recipient); + + LayerAttachPointComponent* GetDefaultLayer(); + LayerAttachPointComponent* GetRootLayer(); + + osg::Group* GetSceneGraphRoot() + { + return mSceneGraphRoot.get(); + } + + void CreateSceneGraphRootEntity(osg::Group* root); + + dtEntity::Property* ScriptGetByName(const dtEntity::PropertyArgs& args); + + private: + + void RegisterByName(dtEntity::StringId, LayerAttachPointComponent*); + typedef std::map LayerByNameMap; + LayerByNameMap mLayerByNameMap; + osg::ref_ptr mSceneGraphRoot; + dtEntity::EntityId mBaseEntityId; + }; + + +} diff --git a/external/dtEntity/include/dtEntityOSG/layercomponent.h b/external/dtEntity/include/dtEntityOSG/layercomponent.h new file mode 100644 index 000000000..8a2c6b9ee --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/layercomponent.h @@ -0,0 +1,198 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include + +namespace dtEntityOSG +{ + + class LayerAttachPointComponent; + //////////////////////////////////////////////////////////////////////////////// + + struct EntityData : public osg::Referenced + { + dtEntity::Entity* mEntity; + EntityData(dtEntity::Entity* e) + : mEntity(e) + { + } + }; + + /** + * Each visible entity has to have a layer component. The layer component + * defines which node component of the entity is attached to which layer. + */ + class DTENTITY_OSG_EXPORT LayerComponent + : public dtEntity::Component + { + + friend class LayerSystem; + + public: + + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId LayerId; + static const dtEntity::StringId AttachedComponentId; + static const dtEntity::StringId VisibleId; + + LayerComponent(); + virtual ~LayerComponent(); + + virtual dtEntity::ComponentType GetType() const + { + return TYPE; + } + + /** + * The attached component is the component that should be attached + * to the layer. A component with this type has to be present on + * the entity and it has to derive from NodeComponent. + */ + void SetAttachedComponent(dtEntity::ComponentType ctype); + dtEntity::ComponentType GetAttachedComponent() const; + + virtual void OnAddedToEntity(dtEntity::Entity &entity); + + void OnAddedToScene(); + void OnRemovedFromScene(); + + /** + * Attach the entity to the layer with this name. Default value is DefaultLayerId + */ + dtEntity::StringId GetLayer() const; + void SetLayer(dtEntity::StringId); + + /** + * Is the AttachedComponent currently attached to the layer node? + */ + bool IsVisible() const; + + /** + * Set to false to detach AttachedComponent from the layer node. + * Re-attach by setting to true. + */ + void SetVisible(bool); + + /** + * Is the entity already added to scene? Can be used to query current initialization status + */ + bool IsAddedToScene() const { return mAddedToScene; } + + /** + * Get OSG node of attached component + */ + osg::Node* GetAttachedComponentNode() const; + + /** + * @return bool if geometry is attached to layer component + */ + bool GetBoundingBox(dtEntity::Vec3d& min, dtEntity::Vec3d& max); + + /** + * Add attached component node to layer as a child in the scene graph hierarchy + */ + bool Attach(LayerAttachPointComponent* current); + + /** + * Add attached component node to layer as a child in the scene graph hierarchy + */ + bool Detach(LayerAttachPointComponent* current); + + private: + + // is there an attach point, a component to attach and added to scene? + bool CanAttach(); + dtEntity::Entity* mEntity; + dtEntity::DynamicBoolProperty mVisible; + bool mVisibleVal; + dtEntity::DynamicStringIdProperty mLayer; + dtEntity::StringId mLayerVal; + dtEntity::DynamicStringIdProperty mAttachedComponent; + dtEntity::StringId mAttachedComponentVal; + bool mAddedToScene; + + }; + + LayerAttachPointComponent* GetAttachPoint(dtEntity::EntityManager& em, dtEntity::StringId name); + + + + //////////////////////////////////////////////////////////////////////////////// + + class DTENTITY_OSG_EXPORT LayerSystem + : public dtEntity::DefaultEntitySystem + , public dtEntity::ScriptAccessor + { + public: + + static const dtEntity::ComponentType TYPE; + + static const dtEntity::StringId VisibilityBitsId; + + LayerSystem(dtEntity::EntityManager& em); + ~LayerSystem(); + + void OnEnterWorld(const dtEntity::Message&); + void OnLeaveWorld(const dtEntity::Message&); + + void AddVisibleBoundingBox(dtEntity::EntityId id); + void RemoveVisibleBoundingBox(dtEntity::EntityId id); + void RemoveAllBoundingBoxes(); + + // set or clear these bits when visibility of component is toggled + void SetVisibilityBits(unsigned int bits) { mVisibilityBits.Set(bits); } + unsigned int GetVisibilityBits() const { return mVisibilityBits.Get(); } + + private: + + dtEntity::Property* ScriptAddVisibleBoundingBox(const dtEntity::PropertyArgs& args) + { + AddVisibleBoundingBox(args[0]->UIntValue()); + return NULL; + } + + dtEntity::Property* ScriptRemoveVisibleBoundingBox(const dtEntity::PropertyArgs& args) + { + RemoveVisibleBoundingBox(args[0]->UIntValue()); + return NULL; + } + + dtEntity::Property* ScriptRemoveAllBoundingBoxes(const dtEntity::PropertyArgs& args) + { + RemoveAllBoundingBoxes(); + return NULL; + } + + dtEntity::Property* ScriptGetBoundingSphere(const dtEntity::PropertyArgs& args); + + dtEntity::MessageFunctor mEnterWorldFunctor; + dtEntity::MessageFunctor mLeaveWorldFunctor; + + dtEntity::UIntProperty mVisibilityBits; + + }; +} diff --git a/external/dtEntity/include/dtEntityOSG/lightcomponent.h b/external/dtEntity/include/dtEntityOSG/lightcomponent.h new file mode 100644 index 000000000..b4b212423 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/lightcomponent.h @@ -0,0 +1,112 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler + +*/ + +#include +#include +#include +#include +#include +#include + + +namespace osg +{ + class Light; + class LightSource; +} + +namespace dtEntityOSG +{ + + class DTENTITY_OSG_EXPORT LightComponent : public NodeComponent + { + + typedef NodeComponent BaseClass; + + public: + + static const dtEntity::ComponentType TYPE; + + static const dtEntity::StringId LightNumId; + static const dtEntity::StringId PositionId; + static const dtEntity::StringId AmbientId; + static const dtEntity::StringId DiffuseId; + static const dtEntity::StringId SpecularId; + static const dtEntity::StringId SpotCutoffId; + static const dtEntity::StringId SpotExponentId; + static const dtEntity::StringId DirectionId; + static const dtEntity::StringId ConstantAttenuationId; + static const dtEntity::StringId LinearAttenuationId; + static const dtEntity::StringId QuadraticAttenuationId; + + LightComponent(); + virtual ~LightComponent(); + + virtual dtEntity::ComponentType GetType() const { return TYPE; } + + virtual bool IsInstanceOf(dtEntity::ComponentType id) const + { + return (id == TYPE); + } + + osg::Light* GetLight() { return mLight; } + + private: + + osg::Vec4 GetLightPosition() const; + osg::Vec4 GetAmbient() const; + osg::Vec4 GetDiffuse() const; + osg::Vec4 GetSpecular() const; + osg::Vec3 GetDirection() const; + + osg::Light* mLight; + dtEntity::DynamicIntProperty mLightNum; + dtEntity::DynamicVec4Property mAmbient; + dtEntity::DynamicVec4Property mDiffuse; + dtEntity::DynamicVec4Property mSpecular; + dtEntity::DynamicVec4Property mPosition; + dtEntity::DynamicVec3Property mDirection; + dtEntity::DynamicFloatProperty mConstantAttenuation; + dtEntity::DynamicFloatProperty mLinearAttenuation; + dtEntity::DynamicFloatProperty mQuadraticAttenuation; + dtEntity::DynamicFloatProperty mSpotExponent; + dtEntity:: DynamicFloatProperty mSpotCutOff; + }; + + + //////////////////////////////////////////////////////////////////////////// + + class DTENTITY_OSG_EXPORT LightSystem + : public dtEntity::DefaultEntitySystem + { + typedef dtEntity::DefaultEntitySystem BaseClass; + + public: + static const dtEntity::ComponentType TYPE; + + LightSystem(dtEntity::EntityManager& em); + + private: + + }; +} diff --git a/external/dtEntity/include/dtEntityOSG/manipulatorcomponent.h b/external/dtEntity/include/dtEntityOSG/manipulatorcomponent.h new file mode 100644 index 000000000..29ee9b6b8 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/manipulatorcomponent.h @@ -0,0 +1,153 @@ +#pragma once + +/* +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include + +namespace dtEntityOSG +{ + + class ManipulatorComponent + : public dtEntityOSG::NodeComponent + { + + typedef dtEntityOSG::NodeComponent BaseClass; + + + public: + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId LayerId; + static const dtEntity::StringId DraggerTypeId; + static const dtEntity::StringId OffsetFromStartId; + static const dtEntity::StringId KeepSizeConstantId; + static const dtEntity::StringId UseLocalCoordsId; + static const dtEntity::StringId PivotAtBottomId; + + static const dtEntity::StringId TabPlaneDraggerId; + static const dtEntity::StringId TabPlaneTrackballDraggerId; + static const dtEntity::StringId TabBoxTrackballDraggerId; + static const dtEntity::StringId TrackballDraggerId; + static const dtEntity::StringId Translate1DDraggerId; + static const dtEntity::StringId Translate2DDraggerId; + static const dtEntity::StringId TranslateAxisDraggerId; + static const dtEntity::StringId TabBoxDraggerId; + static const dtEntity::StringId TerrainTranslateDraggerId; + static const dtEntity::StringId ScaleDraggerId; + + + ManipulatorComponent(); + virtual ~ManipulatorComponent(); + + virtual dtEntity::ComponentType GetType() const { return TYPE; } + virtual bool IsInstanceOf(dtEntity::ComponentType id) const + { + return (id == TYPE); + } + + virtual void OnAddedToEntity(dtEntity::Entity& e); + virtual void OnRemovedFromEntity(dtEntity::Entity& e); + virtual void Finished(); + + osgManipulator::Dragger* GetDragger() const; + + /** + * Attach the dragger to the layer with this name. Default value is DefaultLayerId + */ + dtEntity::StringId GetLayer() const; + void SetLayer(dtEntity::StringId); + + dtEntity::StringId GetDraggerType() const { return mDraggerTypeVal; } + void SetDraggerType(dtEntity::StringId); + + void SetOffsetFromStart(const osg::Vec3d& v); + osg::Vec3d GetOffsetFromStart() const { return mOffsetFromStartVal; } + + void SetUseLocalCoords(bool v); + bool GetUseLocalCoords() const { return mUseLocalCoordsVal; } + + void SetKeepSizeConstant(bool v); + bool GetKeepSizeConstant() const { return mKeepSizeConstantVal; } + + void SetPivotAtBottom(bool v); + bool GetPivotAtBottom() const { return mPivotAtBottomVal; } + + private: + + void RemoveFromParent(); + void AddToLayer(); + + osg::ref_ptr mDraggerCallback; + dtEntity::DynamicStringIdProperty mLayerProperty; + dtEntity::StringId mLayerVal; + dtEntity::StringId mAttachPoint; + dtEntity::DynamicStringIdProperty mDraggerType; + dtEntity::StringId mDraggerTypeVal; + dtEntity::DynamicVec3dProperty mOffsetFromStart; + osg::Vec3 mOffsetFromStartVal; + dtEntity::DynamicBoolProperty mKeepSizeConstant; + bool mKeepSizeConstantVal; + dtEntity::DynamicBoolProperty mUseLocalCoords; + bool mUseLocalCoordsVal; + dtEntity::DynamicBoolProperty mPivotAtBottom; + bool mPivotAtBottomVal; + osg::ref_ptr mDraggerContainer; + + }; + + + //////////////////////////////////////////////////////////////////////////////// + + class ManipulatorSystem + : public dtEntity::DefaultEntitySystem + { + typedef dtEntity::DefaultEntitySystem BaseClass; + + public: + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId UseLocalCoordsId; + static const dtEntity::StringId UseGroundClampingId; + + ManipulatorSystem(dtEntity::EntityManager& em); + ~ManipulatorSystem(); + + // don't store manipulators to map + virtual bool StoreComponentsToMap() const { return false; } + + // don't copy manipulators with entities, also don't store to spawners + virtual bool AllowComponentCreationBySpawner() const { return false; } + + void SetUseLocalCoords(bool v); + bool GetUseLocalCoords() const { return mUseLocalCoordsVal; } + + void SetUseGroundClamping(bool v) { mUseGroundClamping.Set(v); } + bool GetUseGroundClamping() const { return mUseGroundClamping.Get(); } + + private: + + dtEntity::DynamicBoolProperty mUseLocalCoords; + bool mUseLocalCoordsVal; + dtEntity::BoolProperty mUseGroundClamping; + }; +} diff --git a/external/dtEntity/include/dtEntityOSG/manipulators.h b/external/dtEntity/include/dtEntityOSG/manipulators.h new file mode 100644 index 000000000..77a5bd2d0 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/manipulators.h @@ -0,0 +1,96 @@ +#pragma once + +/* +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace dtEntityOSG +{ + + class TerrainTranslateDragger : public osgManipulator::CompositeDragger + { + typedef osgManipulator::CompositeDragger BaseClass; + + public: + + TerrainTranslateDragger(); + virtual void setupDefaultGeometry(); + virtual bool handle(const osgManipulator::PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa); + + private: + osg::ref_ptr _xDragger; + osg::ref_ptr _yDragger; + osg::ref_ptr _zDragger; + osg::ref_ptr _translate2DDragger; + }; + + + //////////////////////////////////////////////////////////////////////////////// + class ScaleAllDragger : public osgManipulator::Dragger + { + public: + virtual bool handle(const osgManipulator::PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us); + + protected: + osg::Vec2 _startPoint; + osg::Matrix _localToWorld; + osg::Matrix _worldToLocal; + }; + + + //////////////////////////////////////////////////////////////////////////////// + class ScaleDragger : public osgManipulator::CompositeDragger + { + typedef osgManipulator::CompositeDragger BaseClass; + + public: + + ScaleDragger(); + virtual void setupDefaultGeometry(); + virtual bool handle(const osgManipulator::PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa); + + private: + void setupGeometry(osgManipulator::Scale1DDragger*, const osg::Vec4& color); + osg::ref_ptr _xDragger; + osg::ref_ptr _yDragger; + osg::ref_ptr _zDragger; + osg::ref_ptr _scaleAllDragger; + }; + + //////////////////////////////////////////////////////////////////////////////// + class TrackballDragger : public osgManipulator::TrackballDragger + { + typedef osgManipulator::TrackballDragger BaseClass; + public: + virtual bool handle(const osgManipulator::PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa); + + }; +} diff --git a/external/dtEntity/include/dtEntityOSG/matrixtransformcomponent.h b/external/dtEntity/include/dtEntityOSG/matrixtransformcomponent.h new file mode 100644 index 000000000..c268e5e6e --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/matrixtransformcomponent.h @@ -0,0 +1,128 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include +#include + +namespace osg +{ + class MatrixTransform; +} + +namespace dtEntityOSG +{ + + + /////////////////////////////////////////////////////////////////////////// + /** + * holds a single matrix transform + */ + class DTENTITY_OSG_EXPORT MatrixTransformComponent + : public TransformComponent + { + typedef TransformComponent BaseClass; + + public: + + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId MatrixId; + + MatrixTransformComponent(); + MatrixTransformComponent(osg::MatrixTransform* trans); + + virtual ~MatrixTransformComponent(); + + virtual dtEntity::ComponentType GetType() const { + return TYPE; + } + + + const osg::MatrixTransform* GetMatrixTransform() const; + osg::MatrixTransform* GetMatrixTransform(); + + virtual dtEntity::Matrix GetMatrix() const; + virtual void SetMatrix(const dtEntity::Matrix& m); + + virtual dtEntity::Vec3d GetTranslation() const + { + dtEntity::Matrix m = GetMatrix(); + return m.getTrans(); + } + + virtual void SetTranslation(const dtEntity::Vec3d& t) + { + dtEntity::Matrix m = GetMatrix(); + m.setTrans(t); + SetMatrix(m); + } + + virtual dtEntity::Quat GetRotation() const + { + dtEntity::Matrix m = GetMatrix(); + return m.getRotate(); + } + + virtual void SetRotation(const dtEntity::Quat& q) + { + dtEntity::Matrix m = GetMatrix(); + m.setRotate(q); + SetMatrix(m); + } + + virtual dtEntity::Vec3d GetScale() const + { + dtEntity::Matrix m = GetMatrix(); + return m.getScale(); + } + + virtual void SetScale(const dtEntity::Vec3d& v) + { + dtEntity::Matrix m = GetMatrix(); + m = m.scale(v); + SetMatrix(m); + } + + private: + + dtEntity::DynamicMatrixProperty mMatrix; + }; + + + /////////////////////////////////////////////////////////////////////////// + // storage only + class DTENTITY_OSG_EXPORT MatrixTransformSystem + : public dtEntity::DefaultEntitySystem + { + public: + MatrixTransformSystem(dtEntity::EntityManager& em) + : dtEntity::DefaultEntitySystem(em, TransformComponent::TYPE) + { + + } + }; + +} diff --git a/external/dtEntity/include/dtEntityOSG/nodecomponent.h b/external/dtEntity/include/dtEntityOSG/nodecomponent.h new file mode 100644 index 000000000..c7b80d149 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/nodecomponent.h @@ -0,0 +1,113 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include +#include + +namespace dtEntityOSG +{ + + class DTENTITY_OSG_EXPORT NodeStore + { + public: + + NodeStore(); + NodeStore(osg::Node* node); + virtual ~NodeStore(); + + /** + * returns encapsulated node + */ + virtual osg::Node* GetNode() const; + + /** + * Sets encapsulated node. Also, if the currently held node + * is attached as a child to another component then it is + * removed from that parent and the passed node is added as a child + */ + virtual void SetNode(osg::Node* node); + + /** + * type of compponent that this node component is attached to. + * Is 0 if not attached to a parent + */ + dtEntity::ComponentType GetParentComponent() const { return mParentComponent; } + void SetParentComponent(dtEntity::ComponentType c) { mParentComponent = c; } + + void ClearFromParent(); + + void SetNodeMask(unsigned int nodemask, bool recursive = false); + unsigned int GetNodeMask() const; + + void SetNodeEntity(dtEntity::Entity*); + dtEntity::Entity* GetNodeEntity(); + + private: + osg::ref_ptr mNode; + dtEntity::ComponentType mParentComponent; + }; + /////////////////////////////////////////////////////////////////////////// + /** + * Holds a single OSG node. Subclass this if you want to wrap an object + * derived from osg::Node. NodeComponent instances can be attached to + * the scene by the Layer system. + */ + class DTENTITY_OSG_EXPORT NodeComponent + : public dtEntity::Component + , public NodeStore + { + + public: + + static const dtEntity::ComponentType TYPE; + + NodeComponent(); + NodeComponent(osg::Node* node); + virtual ~NodeComponent(); + + virtual dtEntity::ComponentType GetType() const { return TYPE; } + + virtual void OnAddedToEntity(dtEntity::Entity& entity); + virtual void OnRemovedFromEntity(dtEntity::Entity& entity); + + protected: + + }; + + + /////////////////////////////////////////////////////////////////////////// + // storage only + class DTENTITY_OSG_EXPORT NodeSystem + : public dtEntity::DefaultEntitySystem + { + public: + NodeSystem(dtEntity::EntityManager& em) + : dtEntity::DefaultEntitySystem(em) + { + + } + };} diff --git a/external/dtEntity/include/dtEntityOSG/nodemaskvisitor.h b/external/dtEntity/include/dtEntityOSG/nodemaskvisitor.h new file mode 100644 index 000000000..385b706fc --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/nodemaskvisitor.h @@ -0,0 +1,49 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + + +#include +#include + +namespace dtEntityOSG +{ + class NodeMaskVisitor : public osg::NodeVisitor + { + public: + + NodeMaskVisitor(unsigned int mask) : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) + { + mMask = mask; + } + + virtual void apply(osg::Group& node) + { + node.setNodeMask(mMask); + this->traverse(node); + } + + private: + + unsigned int mMask; + }; +} + diff --git a/external/dtEntity/include/dtEntityOSG/osganimationcomponent.h b/external/dtEntity/include/dtEntityOSG/osganimationcomponent.h new file mode 100644 index 000000000..eac7152ac --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/osganimationcomponent.h @@ -0,0 +1,120 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace dtEntityOSG +{ + + /////////////////////////////////////////////////////////////////////////// + class DTENTITY_OSG_EXPORT OSGAnimationComponent : public dtEntity::Component + { + + public: + + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId EnabledId; + + OSGAnimationComponent(); + virtual ~OSGAnimationComponent(); + + virtual dtEntity::ComponentType GetType() const { return TYPE; } + virtual void OnAddedToEntity(dtEntity::Entity& entity); + + osgAnimation::BasicAnimationManager* GetAnimationManager() const + { + return mAnimationManager; + } + + void SetupMesh(osg::Node*); + + void SetEnabled(bool); + bool GetEnabled() const; + + bool AddAttachment(const std::string& boneName, osg::Node* node, const osg::Matrix& m); + bool RemoveAtachment(const std::string& boneName, osg::Node* node); + void RemoveAtachments(const std::string& boneName); + + private: + + osg::ref_ptr mAnimationManager; + dtEntity::Entity* mEntity; + dtEntity::DynamicBoolProperty mEnabled; + bool mEnabledVal; + + }; + + + /////////////////////////////////////////////////////////////////////////// + // storage only + class DTENTITY_OSG_EXPORT OSGAnimationSystem + : public dtEntity::DefaultEntitySystem + , public dtEntity::ScriptAccessor + { + public: + + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId VertexShaderId; + static const dtEntity::StringId FragmentShaderId; + static const dtEntity::StringId EnabledId; + + OSGAnimationSystem(dtEntity::EntityManager& em); + ~OSGAnimationSystem(); + + void OnMeshChanged(const dtEntity::Message&); + + void SetVertexShader(const std::string& v) { mVertexShader.Set(v); } + std::string GetVertexShader() const { return mVertexShader.Get(); } + + void SetFragmentShader(const std::string& v) { mFragmentShader.Set(v); } + std::string GetFragmentShader() const { return mFragmentShader.Get(); } + + void SetEnabled(bool); + bool GetEnabled() const; + + private: + + bool GetAnimationList(dtEntity::EntityId id, const osgAnimation::AnimationList*& list, + osgAnimation::BasicAnimationManager*& manager); + dtEntity::Property* ScriptPlayAnimation(const dtEntity::PropertyArgs& args); + dtEntity::Property* ScriptStopAnimation(const dtEntity::PropertyArgs& args); + dtEntity::Property* ScriptGetAnimations(const dtEntity::PropertyArgs& args); + dtEntity::Property* ScriptGetAnimationLength(const dtEntity::PropertyArgs& args); + dtEntity::Property* ScriptGetAnimationPlayMode(const dtEntity::PropertyArgs& args); + dtEntity::Property* ScriptSetAnimationPlayMode(const dtEntity::PropertyArgs& args); + dtEntity::Property* ScriptAddAttachment(const dtEntity::PropertyArgs& args); + dtEntity::Property* ScriptRemoveAttachments(const dtEntity::PropertyArgs& args); + + dtEntity::MessageFunctor mMeshChangedFunctor; + dtEntity::StringProperty mVertexShader; + dtEntity::StringProperty mFragmentShader; + bool mEnabledVal; + dtEntity::DynamicBoolProperty mEnabled; + }; +} diff --git a/external/dtEntity/include/dtEntityOSG/osgdebugdrawinterface.h b/external/dtEntity/include/dtEntityOSG/osgdebugdrawinterface.h new file mode 100644 index 000000000..457a4449c --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/osgdebugdrawinterface.h @@ -0,0 +1,293 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include +#include + +namespace osg +{ + class Geode; + class Geometry; +} + +namespace dtEntityOSG +{ + + + /** + * Can be used to add simple debug geometry to the scene. Each debug graphics primitive is added + * together with a lifetime / duration. + * If you want to do per-frame drawing, simply set a duration of 0 and + * execute the draw each frame. + * Warning: To use, first do SetEnabled(true), it is off by default! + */ + class DTENTITY_OSG_EXPORT OSGDebugDrawInterface + : public dtEntity::DebugDrawInterface + { + public: + + /** + * Constructor. + * @param layer Add debug draw manager to layer of this name + */ + OSGDebugDrawInterface(dtEntity::EntityManager& em, + dtEntity::StringId layer = dtEntity::StringId()); + ~OSGDebugDrawInterface(); + + /** + * message functors, don't call directly + */ + void Tick(const dtEntity::Message& msg); + void OnEnable(const dtEntity::Message& m); + + /** + * Draw a single point + * @param position Draw point here + * @param color Draw with this color + * @param size Size of points in pixels + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + void AddPoint(const dtEntity::Vec3f& position, const dtEntity::Vec4f& color, + int size = 1, float duration = 0, bool depthTestEnabled = true); + + /** + * Draw multiple points + * @param positions A vector of point positions + * @param color Draw with this color + * @param size Size of points in pixels + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + void AddPoints(const std::vector& positions, const dtEntity::Vec4f& color, + int size = 1, float duration = 0, bool depthTestEnabled = true); + + /** + * Draw a single line + * @param start Line starts here + * @param end Line ends here + * @param color Draw with this color + * @param linewidth Width of line in pixels + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + void AddLine(const dtEntity::Vec3f& start, const dtEntity::Vec3f& end, + const dtEntity::Vec4f& color, int linewidth = 1, float duration = 0, + bool depthTestEnabled = true); + + /** + * Draw a number of lines + * @param lines A vector containing two entries for each line. So to draw two lines you have to have four entries. + * @param color Draw with this color + * @param linewidth Width of line in pixels + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + void AddLines(const std::vector& lines, const dtEntity::Vec4f& color, + int linewidth = 1, float duration = 0, bool depthTestEnabled = true); + + /** + * Draw a 3d cross + * @param position Draw point here + * @param color Draw with this color + * @param size length of each arm + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + void AddCross(const dtEntity::Vec3f& position, const dtEntity::Vec4f& color, float size, + float duration = 0, bool depthTestEnabled = true); + + /** + * Draw a sphere + * @param position Draw sphere here + * @param radius radius of sphere + * @param color Draw with this color + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + void AddSphere(const dtEntity::Vec3f& position, float radius, const dtEntity::Vec4f& color, + float duration = 0, bool depthTestEnabled = true); + + /** + * Draw a single triangle + * @param vert0 First vertex of triangle + * @param vert1 Second vertex of triangle + * @param vert2 Third vertex of triangle + * @param color Draw with this color + * @param lineWidth with of line to draw in pixels + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + void AddTriangle(const dtEntity::Vec3f& vert0, const dtEntity::Vec3f& vert1, + const dtEntity::Vec3f& vert2, const dtEntity::Vec4f& color, + int lineWidth, float duration = 0, bool depthTestEnabled = true); + + /** + * Draw multiple triangles + * @param verts A vector containing triangle verts. The vector should contain three entries for each triangle. + * @param color Draw with this color + * @param lineWidth with of line to draw in pixels + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + void AddTriangles(const std::vector& verts, const dtEntity::Vec4f& color, + int lineWidth, float duration = 0, bool depthTestEnabled = true); + + /** + * Draw a mesh + * @param geometry The OSG geometry that should be drawn + * @param position Draw geometry here + * @param lineColor Draw wireframe with this color. If alpha value is 0 then wireframe will not be drawn + * @param lineWidth Draw wireframe with this line with. If value is 0 then wireframe will not be drawn + * @param faceColor Draw polygons with this color. Blending is enabled, so feel free to set an alpha value. + * Alpha value 0 means no polygons are drawn + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + void AddMesh(osg::Geometry* geometry, const dtEntity::Vec3f& position, + const dtEntity::Vec4f& lineColor, int lineWidth, + const dtEntity::Vec4f& faceColor, float duration = 0, + bool depthTestEnabled = true); + + /** + * Draw a circle + * @param position Center of circle is here + * @param planeNormal A normal vector pointing away from the face of the disk + * @param radius Radius of disk + * @param color Draw with this color + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + void AddCircle(const dtEntity::Vec3f& position, const dtEntity::Vec3f& planeNormal, + float radius, const dtEntity::Vec4f& color, float duration = 0, + bool depthTestEnabled = true); + + /** + * Draw a text string + * @param position Draw text here + * @param str The text to draw + * @param color Draw with this color + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + void AddString(const dtEntity::Vec3f& position, const std::string& str, + const dtEntity::Vec4f& color, float duration = 0, bool depthTestEnabled = true); + + /** + * Draw an axis aligned bounding box + * @param minCoords start box from here + * @param maxCoords end box here + * @param color Draw with this color + * @param lineWidth with of line to draw + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + void AddAABB(const dtEntity::Vec3f& minCoords, const dtEntity::Vec3f& maxCoords, + const dtEntity::Vec4f& color, int lineWidth, float duration = 0, + bool depthTestEnabled = true); + + /** + * Add an oriented bounding box + * @param matrix transformation matrix to apply to box + * @param minCoords start box from here + * @param maxCoords end box here + * @param color Draw with this color + * @param lineWidth with of line to draw + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + void AddOBB(const dtEntity::Matrix& matrix, const dtEntity::Vec3f& minCoords, + const dtEntity::Vec3f& maxCoords, const dtEntity::Vec4f& color, + int lineWidth, float duration = 0, bool depthTestEnabled = true); + + /** + * Add a cross showing coordinate orientation + * @param matrix transformation cross by this matrix + * @param color Draw with this color + * @param size length of cross arms + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + void AddAxes(const dtEntity::Matrix& matrix, const dtEntity::Vec4f& color, + float size, float duration = 0, bool depthTestEnabled = true); + + /** + * Add an OSG drawable + * @param drawable Add this drawable + * @param duration Show for how many seconds. Value 0 means draw once + * @param depthTestEnabled if false, always draw on top + */ + void AddDrawable(osg::Drawable* drawable, float duration = 0, + bool depthTestEnabled = true); + + /** + * DebugDrawInterface is disabled by default, enable it! + */ + void SetEnabled(bool enabled); + bool IsEnabled() const; + + /** + * Immediately remove all debug geometry + */ + void Clear(); + + /** + If context id is set then a redraw of that context is requested from OSG. + Only relevant when render on demand is used. + */ + void SetContextId(unsigned int v) + { + mContextId = v; + mContextIdSet = true; + } + unsigned int GetContextId() const { return mContextId; } + + private: + bool mEnabled; + + // osg group with stateset depth test enabled + osg::ref_ptr mGroupDepthTest; + + // osg group with stateset depth test disabled + osg::ref_ptr mGroupNoDepthTest; + + double mCurrentTime; + dtEntity::EntityManager* mEntityManager; + dtEntity::MessageFunctor mEnableFunctor; + dtEntity::MessageFunctor mTickFunctor; + dtEntity::StringId mLayerName; + int mContextId; + bool mContextIdSet; + void RequestRedraw(); + }; + + inline OSGDebugDrawInterface* GetOSGDebugDrawInterface() + { + return static_cast(dtEntity::GetDebugDrawInterface()); + } +} + diff --git a/external/dtEntity/include/dtEntityOSG/osginputinterface.h b/external/dtEntity/include/dtEntityOSG/osginputinterface.h new file mode 100644 index 000000000..ad4c932ce --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/osginputinterface.h @@ -0,0 +1,237 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include + +namespace dtEntity +{ + class MessagePump; +} + +namespace dtEntityOSG +{ + + //////////////////////////////////////////////////////////////////////////////// + // for use with GuiEventAdapter user event + class MouseEnterLeaveEvent : public osg::Referenced + { + public: + bool mFocused; + }; + + //////////////////////////////////////////////////////////////////////////////// + class DTENTITY_OSG_EXPORT OSGInputInterface + : public dtEntity::InputInterface + { + public: + + + // can't make OSGInputInterface derive from osgGA::GUIEventHandler because + // we don't want to inherit osg::Referenced stuff + class EventHandler : public osgGA::GUIEventHandler + { + OSGInputInterface* mIface; + public: + EventHandler(OSGInputInterface* i) + : mIface(i) + { + } + + virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object* o, osg::NodeVisitor* nv) + { + return mIface->handle(ea, aa, o, nv); + } + + }; + + osgGA::GUIEventHandler* GetEventHandler() { return mEventHandler; } + + typedef std::map KeyNames; + typedef std::map KeyNamesReverse; + + OSGInputInterface(dtEntity::MessagePump&); + virtual ~OSGInputInterface(); + + //virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); + virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor*); + + virtual void AddInputCallback(dtEntity::InputCallbackInterface*); + virtual bool RemoveInputCallback(dtEntity::InputCallbackInterface*); + + /** + * Stores if current system is multitouch-capable + */ + virtual bool GetMultiTouchEnabled() const { return mMultiTouchEnabled; } + virtual void SetMultiTouchEnabled(bool v) { mMultiTouchEnabled = v; } + + virtual bool GetLockCursor() const { return mLockCursor; } + virtual void SetLockCursor(bool v) { mLockCursor = v; } + + /** + * Multitouch interface: return number of touch points + */ + virtual size_t GetNumTouches() const { return mNumTouches; } + + /** + * Multitouch interface: return touch points + */ + virtual std::vector GetTouches() const { return mTouches; } + + /** + * Return true if key is pressed, else false + */ + bool GetKey(const std::string& name, unsigned int contextId = 0) const; + + /** + * Return true if key was released this frame, else false + */ + virtual bool GetKeyUp(const std::string& name, unsigned int contextId = 0) const; + + /** + * Return true if key was pressed down this frame, else false + */ + virtual bool GetKeyDown(const std::string& name, unsigned int contextId = 0) const; + + /** + * Returns true if any keyboard key is currently pressed + */ + virtual bool AnyKeyDown() const; + + /** + * Return string entered this frame + */ + virtual std::string GetInputString() const; + + /** + * Return true if given mouse button is currently pressed. + * 0 for left button, 1 for right, 2 for center + */ + virtual bool GetMouseButton(int button, unsigned int contextId = 0) const; + + /** + * Return true if given mouse button was pressed this frame. + * 0 for left button, 1 for right, 2 for center + */ + virtual bool GetMouseButtonDown(int button, unsigned int contextId = 0) const; + + /** + * Return true if given mouse button was released this frame. + * 0 for left button, 1 for right, 2 for center + */ + virtual bool GetMouseButtonUp(int button, unsigned int contextId = 0) const; + + /** + * Return axis value from -1 to 1 + * @TODO: Axes are currently hard coded + */ + virtual double GetAxis(dtEntity::StringId axisname) const; + + /** + * Return current mouse wheel state. -1 = down, 1 = up, 0 = no motion + */ + virtual int GetMouseWheelState(unsigned int contextId = 0) const; + + /** + * Return a list containing names of all registered keys + */ + void GetKeyNames(std::map&) const; + + /** + * Get OSG key symbol from key name + */ + osgGA::GUIEventAdapter::KeySymbol GetKeySymbol(const std::string& name) const; + + /** + * Clear stuff at end of frame + */ + void Reset(); + + /** + * React to OSG input events + */ + bool handleInternal(const osgGA::GUIEventAdapter& ea); + + + private: + + osg::ref_ptr mEventHandler; + + void HandleMultiTouch(const osgGA::GUIEventAdapter& ea); + void HandleKeyUp(const osgGA::GUIEventAdapter& ea); + void HandleKeyDown(const osgGA::GUIEventAdapter& ea); + void HandleMouseUp(const osgGA::GUIEventAdapter& ea); + void HandleMouseDown(const osgGA::GUIEventAdapter& ea); + void HandleMouseMove(const osgGA::GUIEventAdapter& ea); + void HandleMouseWheel(const osgGA::GUIEventAdapter& ea); + void HandleMouseEnterLeave(const osgGA::GUIEventAdapter& ea); + + dtEntity::MessagePump* mMessagePump; + bool mMultiTouchEnabled; + bool mLockCursor; + size_t mNumTouches; + std::vector mTouches; + + typedef std::vector Callbacks; + Callbacks mCallbacks; + + // pair of context id, key + typedef std::set > ContextKeyMap; + ContextKeyMap mKeyPressedSet; + ContextKeyMap mKeyUpSet; + ContextKeyMap mKeyDownSet; + + KeyNames mKeyNames; + KeyNamesReverse mKeyNamesReverse; + + typedef std::set > ContextButtonMap; + ContextButtonMap mMouseButtonPressed; + ContextButtonMap mMouseButtonUp; + ContextButtonMap mMouseButtonDown; + + float mMouseX; + float mMouseY; + + int mMouseXRaw; + int mMouseYRaw; + int mMouseDeltaXRaw; + int mMouseDeltaYRaw; + float mMouseDeltaX; + float mMouseDeltaY; + + unsigned int mFrameNumber; + int mMouseScroll; + unsigned int mMouseScrollContext; + std::ostringstream mInputString; + + bool mNeedReset; // internal flag to check when to reset + }; + + inline OSGInputInterface* GetOSGInputInterface() + { + return static_cast(dtEntity::GetInputInterface()); + } +} + diff --git a/external/dtEntity/include/dtEntityOSG/osgsysteminterface.h b/external/dtEntity/include/dtEntityOSG/osgsysteminterface.h new file mode 100644 index 000000000..805dcd978 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/osgsysteminterface.h @@ -0,0 +1,101 @@ +#pragma once + +/* -*-c++-*- + * dtEntity Game and Simulation Engine + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library 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 Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Martin Scheffler + */ + +#include +#include +#include +#include +#include + +namespace dtEntity +{ + class MessagePump; +} + +namespace dtEntityOSG +{ + + class DTENTITY_OSG_EXPORT OSGSystemInterface : public dtEntity::SystemInterface + { + public: + + OSGSystemInterface(dtEntity::MessagePump&, int argc, const char** argv); + ~OSGSystemInterface(); + + void InstallUpdateCallback(osg::Node* node); + + void SetViewer(osgViewer::ViewerBase* v) { mViewer = v; } + osgViewer::ViewerBase* GetViewer() const { return mViewer.get(); } + + osgViewer::View* GetPrimaryView() const; + osgViewer::GraphicsWindow* GetPrimaryWindow() const; + osg::Camera* GetPrimaryCamera() const; + + virtual void EmitTickMessagesAndQueuedMessages(); + + virtual void EmitPostUpdateMessage(); + + virtual float GetDeltaSimTime() const; + virtual float GetDeltaRealTime() const; + virtual dtEntity::Timer_t GetRealClockTime(); + virtual double GetSimulationTime() const; + void SetSimulationTime(double); + + virtual float GetTimeScale() const; + virtual void SetTimeScale(float v); + + virtual dtEntity::Timer_t GetSimulationClockTime() const; + virtual void SetSimulationClockTime(dtEntity::Timer_t t); + + void SetTimeValues(double simulationTime, float deltaSimTime,float deltaTime, dtEntity::Timer_t clockTime); + + /** + * Get absolute path from a relative file path. + * Returns empty string if file is not found + */ + virtual std::string FindDataFile(const std::string& filename); + + /** + * return true if a file exists + */ + virtual bool FileExists(const std::string& filename); + + virtual int GetArgC() { return mArgC; } + virtual const char** GetArgV() { return mArgV; } + + private: + osg::observer_ptr mViewer; + dtEntity::MessagePump* mMessagePump; + class Impl; + Impl* mImpl; + + int mArgC; + const char** mArgV; + + }; + + inline OSGSystemInterface* GetOSGSystemInterface() + { + return static_cast(dtEntity::GetSystemInterface()); + } + +} diff --git a/external/dtEntity/include/dtEntityOSG/osgwindowinterface.h b/external/dtEntity/include/dtEntityOSG/osgwindowinterface.h new file mode 100644 index 000000000..260a72532 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/osgwindowinterface.h @@ -0,0 +1,144 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include +#include + +namespace dtEntity +{ + class EntityManager; +} + +namespace osgViewer +{ + class GraphicsWindow; + class View; +} + +namespace dtEntityOSG +{ + + class DTENTITY_OSG_EXPORT OSGWindowInterface : public dtEntity::WindowInterface + { + public: + + struct WindowPos + { + int mX; + int mY; + int mW; + int mH; + bool mWindowDeco; + }; + + OSGWindowInterface(dtEntity::EntityManager& em); + ~OSGWindowInterface(); + + osgViewer::GraphicsWindow* GetWindowByContextId(unsigned int contextId) const; + osgViewer::View* GetViewByContextId(unsigned int contextId) const; + + /** + * Opens a new window if used viewer is a composite viewer. + * @param name Name of osg nodes for window, view and camera to set + * @param traits OSG GraphicsWindow traits to use + * @contextId receives context id of newly created context + * @return true if success, else false + */ + virtual bool OpenWindow(const std::string& name, unsigned int& contextId); + + virtual void CloseWindow(unsigned int contextid); + + /** + * Get pick ray at given screen position + */ + dtEntity::Vec3f GetPickRay(unsigned int contextid, float x, float y, bool usePixels = false) const; + + virtual bool GetWindowGeometry(unsigned int contextid, int& x, int& y, int& width, int& height) const; + virtual bool SetWindowGeometry(unsigned int contextid, int x, int y, int width, int height); + + virtual void SetFullscreen(unsigned int contextid, bool fullscreen); + virtual bool GetFullscreen(unsigned int contextid) const; + + virtual dtEntity::EntityId PickEntity(double x, + double y, + unsigned int nodemask, + unsigned int contextid, + bool usePixels = true) const; + + void SetTraits(osg::GraphicsContext::Traits* traits) { mTraits = traits; } + osg::GraphicsContext::Traits* GetTraits() const { return mTraits; } + + virtual void SetShowCursor(unsigned int contextid, bool); + + virtual dtEntity::Vec3d ConvertWorldToScreenCoords(unsigned int contextid, const dtEntity::Vec3d& coord); + + /** + * Should the window with given context id be continuously redrawn + * or only by request? Default is on + */ + virtual void SetContinuousRedraw(unsigned int contextid, bool); + + /** + * If Continuous Redraw is off, request a redraw in next render traversal + */ + virtual void RequestRedraw(unsigned int contextid); + + /** + * Get intersections between start and end and add them to isects vector + * @param start Start of intersection line + * @param end End of intersection lnie + * @param isects Vector return value for isect results + * @param nodemask Bit mask, used for selecting nodes for intersection + * @param layer Name of layer attach point component from which intersecition test will + * be executed downwards (default: layer "default") + * @return true if an intersection was found + */ + virtual bool GetIntersections(const dtEntity::Vec3d& start, const dtEntity::Vec3d& end, + std::vector& isects, + unsigned int nodemask = dtEntity::NodeMasks::PICKABLE | dtEntity::NodeMasks::TERRAIN, + dtEntity::StringId layer = dtEntity::StringId() + ) const; + + + protected: + + bool OpenWindowInternal(const std::string& name, unsigned int& contextId); + + dtEntity::EntityManager* mEntityManager; + + typedef std::map WindowPosMap; + WindowPosMap mWindowPositions; + osg::ref_ptr mTraits; + + }; + + inline OSGWindowInterface* GetOSGWindowInterface() + { + return static_cast(dtEntity::GetWindowInterface()); + } + +} diff --git a/external/dtEntity/include/dtEntityOSG/particlecomponent.h b/external/dtEntity/include/dtEntityOSG/particlecomponent.h new file mode 100644 index 000000000..cd00fb8cb --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/particlecomponent.h @@ -0,0 +1,231 @@ +#pragma once + +/* +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace dtEntityOSG +{ + + class ParticleComponent + : public dtEntityOSG::NodeComponent + { + + public: + typedef dtEntityOSG::NodeComponent BaseClass; + + static const dtEntity::ComponentType TYPE; + + static const dtEntity::StringId AlphaRangeId; + static const dtEntity::StringId ColorRangeMinId; + static const dtEntity::StringId ColorRangeMaxId; + static const dtEntity::StringId CounterId; + static const dtEntity::StringId DebugOnId; + static const dtEntity::StringId EmissiveParticlesId; + static const dtEntity::StringId EnabledId; + static const dtEntity::StringId LifeTimeId; + static const dtEntity::StringId LightingId; + static const dtEntity::StringId MassId; + static const dtEntity::StringId PlacerId; + static const dtEntity::StringId SizeRangeId; + static const dtEntity::StringId TextureFileId; + static const dtEntity::StringId TextureUnitId; + + static const dtEntity::StringId __SELECTED__Id; + static const dtEntity::StringId BoxId; + static const dtEntity::StringId CompositeId; + static const dtEntity::StringId MultiSegmentId; + static const dtEntity::StringId PointId; + static const dtEntity::StringId SectorId; + static const dtEntity::StringId SegmentId; + + static const dtEntity::StringId XRangeId; + static const dtEntity::StringId YRangeId; + static const dtEntity::StringId ZRangeId; + static const dtEntity::StringId CenterId; + + static const dtEntity::StringId RandomRateCounterId; + static const dtEntity::StringId ConstantRateCounterId; + + static const dtEntity::StringId RateRangeId; + static const dtEntity::StringId MinimumNumberOfParticlesToCreateId; + static const dtEntity::StringId NumberOfParticlesPerSecondToCreateId; + + static const dtEntity::StringId ShooterThetaRangeId; + static const dtEntity::StringId ShooterPhiRangeId; + static const dtEntity::StringId ShooterInitialSpeedRangeId; + static const dtEntity::StringId ShooterInitialRotationalSpeedMinId; + static const dtEntity::StringId ShooterInitialRotationalSpeedMaxId; + + static const dtEntity::StringId ShapeId; + static const dtEntity::StringId ShapePointId; + static const dtEntity::StringId ShapeQuadId; + static const dtEntity::StringId ShapeQuadTriangeStripId; + static const dtEntity::StringId ShapeHexagonId; + static const dtEntity::StringId ShapeLineId; + + static const dtEntity::StringId OperatorsId; + + static const dtEntity::StringId BounceOperatorId; + static const dtEntity::StringId ForceOperatorId; + + static const dtEntity::StringId FrictionId; + static const dtEntity::StringId ResilienceId; + static const dtEntity::StringId CutoffId; + static const dtEntity::StringId DomainsId; + static const dtEntity::StringId PlaneDomainId; + static const dtEntity::StringId SphereDomainId; + static const dtEntity::StringId ForceId; + static const dtEntity::StringId NormalId; + static const dtEntity::StringId DistId; + static const dtEntity::StringId RadiusId; + + + + ParticleComponent(); + virtual ~ParticleComponent(); + + virtual dtEntity::ComponentType GetType() const { return TYPE; } + virtual bool IsInstanceOf(dtEntity::ComponentType id) const + { + return (id == TYPE); + } + + virtual void OnAddedToEntity(dtEntity::Entity &entity); + virtual void OnRemovedFromEntity(dtEntity::Entity &entity); + + virtual void Finished(); + + void SetTextureFile(const std::string& v) { mTextureFile.Set(v); } + std::string GetTextureFile() const { return mTextureFile.Get(); } + + void SetEmissiveParticles(bool v) { mEmissiveParticles.Set(v); } + bool GetEmissiveParticles() const { return mEmissiveParticles.Get(); } + + void SetDebugOn(bool v); + bool GetDebugOn() const { return mDebugOnVal; } + + void SetLighting(bool v) { mLighting.Set(v); } + bool GetLighting() const { return mLighting.Get(); } + + void SetTextureUnit(int v) { mTextureUnit.Set(v); } + int GetTextureUnit() const { return mTextureUnit.Get(); } + + void SetLifeTime(double v) { mLifeTime.Set(v); } + double GetLifeTime() const { return mLifeTime.Get(); } + + void SetMass(float v) { mMass.Set(v); } + float GetMass() const { return mMass.Get(); } + + void SetSizeRange(const osg::Vec2& v) { mSizeRange.Set(v); } + osg::Vec2 GetSizeRange() const { return mSizeRange.Get(); } + + + void SetCounter(const dtEntity::PropertyGroup&); + dtEntity::PropertyGroup GetCounter() const; + + void SetPlacer(const dtEntity::PropertyGroup&); + dtEntity::PropertyGroup GetPlacer() const; + + void SetShooterThetaRange(const osg::Vec2& v); + osg::Vec2 GetShooterThetaRange() const; + + void SetShooterPhiRange(const osg::Vec2& v); + osg::Vec2 GetShooterPhiRange() const; + + void SetShooterInitialSpeedRange(const osg::Vec2& v); + osg::Vec2 GetShooterInitialSpeedRange() const; + + void SetShooterInitialRotationalSpeedMin(const osg::Vec3& v); + osg::Vec3 GetShooterInitialRotationalSpeedMin() const; + + void SetShooterInitialRotationalSpeedMax(const osg::Vec3& v); + osg::Vec3 GetShooterInitialRotationalSpeedMax() const; + + void SetOperators(const dtEntity::PropertyArray& v); + dtEntity::PropertyArray GetOperators() const; + + protected: + + osg::ref_ptr mGeode; + osg::ref_ptr mParticleSystem; + osg::ref_ptr mModularEmitter; + osg::ref_ptr mProgram; + + dtEntity::DynamicBoolProperty mDebugOn; + bool mDebugOnVal; + dtEntity::StringProperty mTextureFile; + dtEntity::BoolProperty mEmissiveParticles; + dtEntity::BoolProperty mEnabled; + dtEntity::BoolProperty mLighting; + dtEntity::IntProperty mTextureUnit; + + dtEntity::DoubleProperty mLifeTime; + dtEntity::FloatProperty mMass; + dtEntity::Vec2Property mSizeRange; + dtEntity::Vec2Property mAlphaRange; + dtEntity::Vec4Property mColorRangeMin; + dtEntity::Vec4Property mColorRangeMax; + + dtEntity::DynamicGroupProperty mPlacer; + dtEntity::GroupProperty mPlacerVal; + dtEntity::DynamicGroupProperty mCounter; + dtEntity::GroupProperty mCounterVal; + + dtEntity::DynamicVec2Property mShooterThetaRange; + dtEntity::DynamicVec2Property mShooterPhiRange; + dtEntity::DynamicVec2Property mShooterInitialSpeedRange; + dtEntity::DynamicVec3Property mShooterInitialRotationalSpeedMin; + dtEntity::DynamicVec3Property mShooterInitialRotationalSpeedMax; + + dtEntity::StringIdProperty mShape; + + dtEntity::DynamicArrayProperty mOperators; + dtEntity::ArrayProperty mOperatorsVal; + + }; + + + //////////////////////////////////////////////////////////////////////////////// + + class ParticleSystem + : public dtEntity::DefaultEntitySystem + { + typedef dtEntity::DefaultEntitySystem BaseClass; + + public: + + static const dtEntity::ComponentType TYPE; + + ParticleSystem(dtEntity::EntityManager& em); + ~ParticleSystem(); + + }; +} diff --git a/external/dtEntity/include/dtEntityOSG/pathcomponent.h b/external/dtEntity/include/dtEntityOSG/pathcomponent.h new file mode 100644 index 000000000..253da74e4 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/pathcomponent.h @@ -0,0 +1,98 @@ +#pragma once + +/* +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include + +namespace dtEntityOSG +{ + + class PathComponent : public dtEntityOSG::NodeComponent + { + typedef dtEntityOSG::NodeComponent BaseClass; + + public: + + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId VertsId; + static const dtEntity::StringId PathVisibleId; + static const dtEntity::StringId VertsVisibleId; + + typedef dtEntity::PropertyArray::size_type size_type; + + PathComponent(); + virtual ~PathComponent(); + + virtual dtEntity::ComponentType GetType() const { return TYPE; } + virtual bool IsInstanceOf(dtEntity::ComponentType id) const + { + return (id == TYPE); + } + + virtual void Finished(); + + void SetPathsVisible(bool v) { mPathsVisible.Set(v); } + bool GetPathsVisible() const { return mPathsVisible.Get(); } + + void SetVertsVisible(bool v) { mVertsVisible.Set(v); } + bool GetVertsVisible() const { return mVertsVisible.Get(); } + + osg::Vec3 GetVertex(size_type index) const; + void SetVertex(size_type index, const osg::Vec3& v); + size_type GetNumVertices() const; + + private: + + dtEntity::ArrayProperty mVerts; + dtEntity::BoolProperty mPathsVisible; + dtEntity::BoolProperty mVertsVisible; + }; + + + //////////////////////////////////////////////////////////////////////////////// + + class PathSystem + : public dtEntity::DefaultEntitySystem + , public dtEntity::ScriptAccessor + { + typedef dtEntity::DefaultEntitySystem BaseClass; + + public: + + static const dtEntity::ComponentType TYPE; + + PathSystem(dtEntity::EntityManager& em); + ~PathSystem(); + + dtEntity::Property* ScriptPickVertex(const dtEntity::PropertyArgs& args); + dtEntity::Property* ScriptGetVertexWorldPosition(const dtEntity::PropertyArgs& args); + dtEntity::Property* ScriptSetVertexWorldPosition(const dtEntity::PropertyArgs& args); + dtEntity::Property* ScriptDuplicateVertex(const dtEntity::PropertyArgs& args); + + private: + + }; +} diff --git a/external/dtEntity/include/dtEntityOSG/pickshapecomponent.h b/external/dtEntity/include/dtEntityOSG/pickshapecomponent.h new file mode 100644 index 000000000..a727b9775 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/pickshapecomponent.h @@ -0,0 +1,96 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace dtEntityOSG +{ + + /////////////////////////////////////////////////////////////////////////// + + /** + * Adds a pickable shape to the transform of the entity + */ + class DTENTITY_OSG_EXPORT PickShapeComponent + : public NodeComponent + { + public: + + typedef NodeComponent BaseClass; + + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId MinBoundsId; + static const dtEntity::StringId MaxBoundsId; + static const dtEntity::StringId VisibleId; + + PickShapeComponent(); + virtual ~PickShapeComponent(); + + virtual dtEntity::ComponentType GetType() const { return TYPE; } + + void SetMinBounds(const osg::Vec3& v); + osg::Vec3 GetMinBounds() const { return mMinBoundsVal; } + + void SetMaxBounds(const osg::Vec3& v); + osg::Vec3 GetMaxBounds() const { return mMaxBoundsVal; } + + void SetVisible(bool v); + bool GetVisible() const; + + private: + + void UpdatePickShape(); + + // path to loaded script file + dtEntity::StringProperty mMeshPathProperty; + dtEntity::DynamicVec3Property mMinBounds; + dtEntity::DynamicVec3Property mMaxBounds; + dtEntity::DynamicBoolProperty mVisible; + osg::ref_ptr mBox; + osg::Vec3 mMinBoundsVal; + osg::Vec3 mMaxBoundsVal; + + }; + + + ////////////////////////////////////////////////////////// + + class DTENTITY_OSG_EXPORT PickShapeSystem + : public dtEntity::DefaultEntitySystem + { + public: + + static const dtEntity::ComponentType TYPE; + + PickShapeSystem(dtEntity::EntityManager& em); + ~PickShapeSystem(); + private: + }; + +} diff --git a/external/dtEntity/include/dtEntityOSG/positionattitudetransformcomponent.h b/external/dtEntity/include/dtEntityOSG/positionattitudetransformcomponent.h new file mode 100644 index 000000000..67b08f3a9 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/positionattitudetransformcomponent.h @@ -0,0 +1,105 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace osg +{ + class PositionAttitudeTransform; +} + +namespace dtEntityOSG +{ + + /////////////////////////////////////////////////////////////////////////// + /** + * holds a single PositionAttitude transform + */ + class DTENTITY_OSG_EXPORT PositionAttitudeTransformComponent + : public TransformComponent + { + typedef TransformComponent BaseClass; + + public: + + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId PositionId; + static const dtEntity::StringId AttitudeId; + static const dtEntity::StringId ScaleId; + + PositionAttitudeTransformComponent(); + + virtual ~PositionAttitudeTransformComponent(); + + virtual dtEntity::ComponentType GetType() const { + return TYPE; + } + + const osg::PositionAttitudeTransform* GetPositionAttitudeTransform() const; + osg::PositionAttitudeTransform* GetPositionAttitudeTransform(); + + dtEntity::Vec3d GetPosition() const; + void SetPosition(const dtEntity::Vec3d& p); + + dtEntity::Quat GetAttitude() const; + void SetAttitude(const dtEntity::Quat& r); + + dtEntity::Vec3d GetScale() const; + void SetScale(const dtEntity::Vec3d& q); + + virtual dtEntity::Vec3d GetTranslation() const { return GetPosition(); } + virtual void SetTranslation(const dtEntity::Vec3d& t) { SetPosition(t); } + + virtual dtEntity::Quat GetRotation() const { return GetAttitude(); } + virtual void SetRotation(const dtEntity::Quat& q) { SetAttitude(q); } + + virtual dtEntity::Matrix GetMatrix() const; + virtual void SetMatrix(const dtEntity::Matrix& mat); + + private: + + dtEntity::DynamicVec3dProperty mPosition; + dtEntity::DynamicVec3dProperty mScale; + dtEntity::DynamicQuatProperty mAttitude; + }; + + /////////////////////////////////////////////////////////////////////////// + // storage only + class DTENTITY_OSG_EXPORT PositionAttitudeTransformSystem + : public dtEntity::DefaultEntitySystem + { + public: + PositionAttitudeTransformSystem(dtEntity::EntityManager& em) + : dtEntity::DefaultEntitySystem(em, TransformComponent::TYPE) + { + + } + }; + +} diff --git a/external/dtEntity/include/dtEntityOSG/shadercomponent.h b/external/dtEntity/include/dtEntityOSG/shadercomponent.h new file mode 100644 index 000000000..1495475f4 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/shadercomponent.h @@ -0,0 +1,101 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include + +namespace osg +{ + class Program; +} + +namespace dtEntityOSG +{ + + class DTENTITY_OSG_EXPORT ShaderComponent : public dtEntity::Component + { + + typedef dtEntity::Component BaseClass; + + public: + + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId MaterialNamePrefixId; + static const dtEntity::StringId TopLevelMaterialNameId; + + ShaderComponent(); + virtual ~ShaderComponent(); + + void OnAddedToEntity(dtEntity::Entity& entity); + + virtual dtEntity::ComponentType GetType() const { return TYPE; } + + std::string GetMaterialNamePrefix() const { return mMaterialNamePrefix.Get(); } + void SetMaterialNamePrefix(const std::string& s) { mMaterialNamePrefix.Set(s); } + + std::string GetTopLevelMaterialName() const { return mTopLevelMaterialName.Get(); } + void SetTopLevelMaterialName(const std::string& s) { mTopLevelMaterialName.Set(s); } + + private: + dtEntity::StringProperty mMaterialNamePrefix; + dtEntity::StringProperty mTopLevelMaterialName; + + }; + + + ////////////////////////////////////////////////////////// + + // storage only + class DTENTITY_OSG_EXPORT ShaderSystem + : public dtEntity::DefaultEntitySystem + , public dtEntity::ScriptAccessor + { + typedef dtEntity::DefaultEntitySystem BaseClass; + + public: + static const dtEntity::ComponentType TYPE; + + ShaderSystem(dtEntity::EntityManager& em); + ~ShaderSystem(); + + void AddProgram(const std::string& name, osg::Program* prg); + osg::Program* GetProgram(const std::string& name) const; + + virtual bool CreateComponent(dtEntity::EntityId eid, dtEntity::Component*& component); + + private: + + typedef std::map > ProgramMap; + ProgramMap mPrograms; + dtEntity::MessageFunctor mChangedMeshFunctor; + + void OnChangedMesh(const dtEntity::Message& msg); + void ApplyShader(dtEntity::EntityId); + dtEntity::Property* ScriptAddProgram(const dtEntity::PropertyArgs& args); + dtEntity::Property* ScriptAddUniform(const dtEntity::PropertyArgs& args); + dtEntity::Property* ScriptRemoveUniform(const dtEntity::PropertyArgs& args); + + }; + +} diff --git a/external/dtEntity/include/dtEntityOSG/shadowcomponent.h b/external/dtEntity/include/dtEntityOSG/shadowcomponent.h new file mode 100644 index 000000000..d2eaf57d5 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/shadowcomponent.h @@ -0,0 +1,111 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include + +namespace dtEntityOSG +{ + + /** + * Holds a single OSG node. + */ + class DTENTITY_OSG_EXPORT ShadowComponent : public GroupComponent + { + typedef GroupComponent BaseClass; + + public: + + static const dtEntity::ComponentType TYPE; + + static const dtEntity::StringId EnabledId; + static const dtEntity::StringId ShadowTechniqueId; + static const dtEntity::StringId MinLightMarginId; + static const dtEntity::StringId MaxFarPlaneId; + static const dtEntity::StringId TexSizeId; + static const dtEntity::StringId BaseTexUnitId; + static const dtEntity::StringId ShadowTexUnitId; + static const dtEntity::StringId ShadowTexCoordIndexId; + static const dtEntity::StringId BaseTexCoordIndexId; + static const dtEntity::StringId MapCountId; + static const dtEntity::StringId MapResId; + static const dtEntity::StringId DebugColorOnId; + static const dtEntity::StringId MinNearSplitId; + static const dtEntity::StringId MaxFarDistId; + static const dtEntity::StringId MoveVCamFactorId; + static const dtEntity::StringId PolyOffsetFactorId; + static const dtEntity::StringId PolyOffsetUnitId; + static const dtEntity::StringId LISPId; + static const dtEntity::StringId PSSMId; + static const dtEntity::StringId __SELECTED__Id; + + static const dtEntity::StringId ShadowTypeId; + + ShadowComponent(); + virtual ~ShadowComponent(); + + void OnAddedToEntity(dtEntity::Entity& entity); + + virtual dtEntity::ComponentType GetType() const { return TYPE; } + + virtual void Finished(); + + void SetShadowTechnique(const std::string name); + + void SetEnabled(bool v) { mEnabled.Set(v); } + bool GetEnabled() const { return mEnabled.Get(); } + private: + + dtEntity::Entity* mEntity; + dtEntity::BoolProperty mEnabled; + osg::ref_ptr mTechnique; + + dtEntity::GroupProperty mShadowType; + }; + + + ////////////////////////////////////////////////////////// + + // storage only + class DTENTITY_OSG_EXPORT ShadowSystem + : public dtEntity::DefaultEntitySystem + { + public: + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId EnabledId; + + ShadowSystem(dtEntity::EntityManager& em); + virtual ~ShadowSystem(); + + void SetEnabled(bool); + bool GetEnabled() const { return mEnabledVal; } + + private: + dtEntity::DynamicBoolProperty mEnabled; + bool mEnabledVal; + }; + +} diff --git a/external/dtEntity/include/dtEntityOSG/skyboxcomponent.h b/external/dtEntity/include/dtEntityOSG/skyboxcomponent.h new file mode 100644 index 000000000..5be38b35a --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/skyboxcomponent.h @@ -0,0 +1,84 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include + +namespace dtEntityOSG +{ + + /** + * Holds a single OSG node. + */ + class DTENTITY_OSG_EXPORT SkyBoxComponent : public GroupComponent + { + + typedef GroupComponent BaseClass; + + public: + + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId TextureUpId; + static const dtEntity::StringId TextureDownId; + static const dtEntity::StringId TextureNorthId; + static const dtEntity::StringId TextureSouthId; + static const dtEntity::StringId TextureEastId; + static const dtEntity::StringId TextureWestId; + + SkyBoxComponent(); + virtual ~SkyBoxComponent(); + + virtual void Finished(); + + virtual dtEntity::ComponentType GetType() const { return TYPE; } + + virtual osg::Group* GetAttachmentGroup() const { return mDrawables; } + + private: + osg::ref_ptr mSkyboxGeode; + dtEntity::StringProperty mTextureUp; + dtEntity::StringProperty mTextureDown; + dtEntity::StringProperty mTextureNorth; + dtEntity::StringProperty mTextureSouth; + dtEntity::StringProperty mTextureEast; + dtEntity::StringProperty mTextureWest; + osg::ref_ptr mDrawables; + }; + + + ////////////////////////////////////////////////////////// + + // storage only + class DTENTITY_OSG_EXPORT SkyBoxSystem + : public dtEntity::DefaultEntitySystem + { + public: + static const dtEntity::ComponentType TYPE; + SkyBoxSystem(dtEntity::EntityManager& em); + }; + +} + diff --git a/external/dtEntity/include/dtEntityOSG/staticmeshcomponent.h b/external/dtEntity/include/dtEntityOSG/staticmeshcomponent.h new file mode 100644 index 000000000..dfb514745 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/staticmeshcomponent.h @@ -0,0 +1,115 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include +#include + +namespace dtEntityOSG +{ + + + /////////////////////////////////////////////////////////////////////////// + /** + * Loads a static mesh from a path + */ + class DTENTITY_OSG_EXPORT StaticMeshComponent + : public NodeComponent + { + public: + + typedef NodeComponent BaseClass; + + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId MeshId; + static const dtEntity::StringId CacheHintId; + static const dtEntity::StringId OptimizeId; + static const dtEntity::StringId IsTerrainId; + + static const dtEntity::StringId CacheNoneId; + static const dtEntity::StringId CacheAllId; + static const dtEntity::StringId CacheNodesId; + static const dtEntity::StringId CacheHardwareMeshesId; + + StaticMeshComponent(); + virtual ~StaticMeshComponent(); + + virtual dtEntity::ComponentType GetType() const { return TYPE; } + + virtual void Finished(); + + // set existing geometry as static mesh + void SetStaticMesh(osg::Node* node); + + /** + * return path of currently loaded mesh + */ + std::string GetMesh() const; + + /** + * Load mesh from path + */ + virtual void SetMesh(const std::string& path, dtEntity::StringId cacheHint = CacheAllId); + + void SetCacheHint(dtEntity::StringId v) { mCacheHint.Set(v); } + dtEntity::StringId GetCacheHint() const { return mCacheHint.Get(); } + + bool GetOptimize() const { return mOptimize.Get(); } + void SetOptimize(bool v) { mOptimize.Set(v); } + + bool GetIsTerrain() const { return mIsTerrainVal; } + void SetIsTerrain(bool v); + + protected: + + // path to loaded script file + dtEntity::StringProperty mMeshPathProperty; + dtEntity::StringIdProperty mCacheHint; + dtEntity::BoolProperty mOptimize; + dtEntity::DynamicBoolProperty mIsTerrain; + bool mIsTerrainVal; + std::string mLoadedMesh; + }; + + + /////////////////////////////////////////////////////////////////////////// + // storage only + class DTENTITY_OSG_EXPORT StaticMeshSystem + : public dtEntity::DefaultEntitySystem + { + public: + + static const dtEntity::ComponentType TYPE; + + StaticMeshSystem(dtEntity::EntityManager& em); + ~StaticMeshSystem(); + + void OnResourceChanged(const dtEntity::Message& msg); + + private: + dtEntity::MessageFunctor mResourceChangedFunctor; + }; +} diff --git a/external/dtEntity/include/dtEntityOSG/textlabelcomponent.h b/external/dtEntity/include/dtEntityOSG/textlabelcomponent.h new file mode 100644 index 000000000..9a8336727 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/textlabelcomponent.h @@ -0,0 +1,157 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include +#include + +namespace dtEntityOSG +{ + class Entity; + class TextLabelSystem; + + class DTENTITY_OSG_EXPORT TextLabelComponent : public NodeComponent + { + + typedef NodeComponent BaseClass; + + public: + + typedef std::vector >::size_type size_type; + + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId TextsId; + static const dtEntity::StringId AlwaysOnTopId; + static const dtEntity::StringId TextId; + static const dtEntity::StringId ColorId; + static const dtEntity::StringId BackdropColorId; + static const dtEntity::StringId VisibleId; + static const dtEntity::StringId HighlightedId; + static const dtEntity::StringId OffsetId; + static const dtEntity::StringId CharacterHeightId; + static const dtEntity::StringId FontId; + static const dtEntity::StringId AlignmentId; + + TextLabelComponent(); + virtual ~TextLabelComponent(); + + virtual dtEntity::ComponentType GetType() const { return TYPE; } + + virtual bool IsInstanceOf(dtEntity::ComponentType id) const + { + return (id == TYPE); + } + + virtual void Finished(); + + void OnAddedToEntity(dtEntity::Entity& entity); + + size_type GetNumTexts() const { return mTextEntries.size(); } + void Create(size_type textid); + void Destroy(size_type textid); + + void ClearAll(); + + void SetText(size_type textid, const std::string&); + std::string GetText(size_type textid) const; + + void SetHighlighted(size_type textid, bool); + bool GetHighlighted(size_type textid) const; + + void SetFlashing(size_type textid, bool); + bool GetFlashing(size_type textid) const; + + void SetColor(size_type textid, const osg::Vec4&); + osg::Vec4 GetColor(size_type textid) const; + + void SetBackdropColor(size_type textid, const osg::Vec4&); + osg::Vec4 GetBackdropColor(size_type textid) const; + + void SetVisible(size_type textid, bool); + bool GetVisible(size_type textid) const; + + void SetFont(size_type textid, const std::string&); + std::string GetFont(size_type textid) const; + + void SetOffset(size_type textid, const osg::Vec3&); + osg::Vec3 GetOffset(size_type textid) const; + + void SetCharacterHeight(size_type textid, float); + float GetCharacterHeight(size_type textid) const; + + void SetAlignment(size_type textid, const std::string& str); + std::string GetAlignment(size_type textid) const; + + bool GetAlwaysOnTop() const { return mAlwaysOnTopVal; } + void SetAlwaysOnTop(bool v); + + private: + + void SetTexts(const dtEntity::PropertyArray& texts); + dtEntity::PropertyArray GetTexts() const; + dtEntity::DynamicArrayProperty mTexts; + dtEntity::ArrayProperty mTextsVal; + dtEntity::DynamicBoolProperty mAlwaysOnTop; + bool mAlwaysOnTopVal; + typedef std::vector > TextEntries; + TextEntries mTextEntries; + TextLabelSystem* mTextLabelSystem; + }; + + + //////////////////////////////////////////////////////////////////////////// + + class DTENTITY_OSG_EXPORT TextLabelSystem + : public dtEntity::DefaultEntitySystem + , public dtEntity::ScriptAccessor + { + static const dtEntity::StringId EnabledId; + typedef dtEntity::DefaultEntitySystem BaseClass; + + public: + + static const dtEntity::ComponentType TYPE; + + TextLabelSystem(dtEntity::EntityManager& em); + + void SetEnabled(bool v); + bool GetEnabled() const; + + private: + + dtEntity::DynamicBoolProperty mEnabled; + bool mEnabledVal; + dtEntity::Property* ScriptCreate(const dtEntity::PropertyArgs& args); + dtEntity::Property* ScriptDestroy(const dtEntity::PropertyArgs& args); + dtEntity::Property* ScriptSetText(const dtEntity::PropertyArgs& args); + dtEntity::Property* ScriptSetOffset(const dtEntity::PropertyArgs& args); + dtEntity::Property* ScriptSetAlignment(const dtEntity::PropertyArgs& args); + dtEntity::Property* ScriptSetColor(const dtEntity::PropertyArgs& args); + dtEntity::Property* ScriptSetBackdropColor(const dtEntity::PropertyArgs& args); + dtEntity::Property* ScriptSetHighlighted(const dtEntity::PropertyArgs& args); + + }; +} diff --git a/external/dtEntity/include/dtEntityOSG/texturelabelcomponent.h b/external/dtEntity/include/dtEntityOSG/texturelabelcomponent.h new file mode 100644 index 000000000..bfa505b47 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/texturelabelcomponent.h @@ -0,0 +1,145 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler + +*/ + +#include +#include +#include +#include +#include +#include +#include + +namespace dtEntityOSG +{ + + class TextureLabelSystem; + + class DTENTITY_OSG_EXPORT TextureLabelComponent : public NodeComponent + { + + friend class TextureLabelSystem; + typedef NodeComponent BaseClass; + + public: + + static const dtEntity::ComponentType TYPE; + static const dtEntity::StringId OffsetId; + static const dtEntity::StringId PathId; + static const dtEntity::StringId ColorId; + static const dtEntity::StringId MaxSizeId; + static const dtEntity::StringId MinSizeId; + static const dtEntity::StringId DistanceAttenuationId; + static const dtEntity::StringId VisibleId; + static const dtEntity::StringId AlwaysOnTopId; + static const dtEntity::StringId AddConnectingLineId; + + TextureLabelComponent(); + virtual ~TextureLabelComponent(); + + virtual dtEntity::ComponentType GetType() const { return TYPE; } + + virtual bool IsInstanceOf(dtEntity::ComponentType id) const + { + return (id == TYPE); + } + + virtual void Finished(); + + virtual void OnAddedToEntity(dtEntity::Entity& entity); + std::string GetPath() const { return mPath.Get(); } + + // call OnFinished...() to apply + void SetPath(const std::string& path) { mPath.Set(path); } + + osg::Geode* GetGeode() const; + + osg::Vec3 GetOffset() const { return mOffsetVal; } + void SetOffset(const osg::Vec3& o); + + void SetMaxSize(unsigned int v) { mMaxSize.Set(v); } + unsigned int GetMaxSize() const { return mMaxSize.Get(); } + + void SetMinSize(unsigned int v) { mMinSize.Set(v); } + unsigned int GetMinSize() const { return mMinSize.Get(); } + + void SetDistanceAttenuation(const osg::Vec3& v) { mDistanceAttenuation.Set(v); } + osg::Vec3 GetDistanceAttenuation() const { return mDistanceAttenuation.Get(); } + + osg::Vec4 GetColor() const { return mColorVal; } + void SetColor(const osg::Vec4& v); + + void SetVisible(bool v); + bool GetVisible() const; + + bool GetAlwaysOnTop() const { return mAlwaysOnTop.Get(); } + void SetAlwaysOnTop(bool v) { mAlwaysOnTop.Set(v); } + + osg::Uniform* GetColorUniform() const { return mColorUniform; } + private: + + osg::ref_ptr mColorArray; + osg::ref_ptr mDotGeometry; + dtEntity::DynamicVec3Property mOffset; + osg::Vec3 mOffsetVal; + dtEntity::DynamicVec4Property mColor; + osg::Vec4 mColorVal; + dtEntity::StringProperty mPath; + dtEntity::UIntProperty mMinSize; + dtEntity::UIntProperty mMaxSize; + dtEntity::Vec3Property mDistanceAttenuation; + dtEntity::DynamicBoolProperty mVisible; + dtEntity::BoolProperty mAlwaysOnTop; + TextureLabelSystem* mLabelSystem; + osg::ref_ptr mColorUniform; + }; + + + //////////////////////////////////////////////////////////////////////////// + + class DTENTITY_OSG_EXPORT TextureLabelSystem + : public dtEntity::DefaultEntitySystem + { + static const dtEntity::StringId EnabledId; + typedef dtEntity::DefaultEntitySystem BaseClass; + + public: + + static const dtEntity::ComponentType TYPE; + + TextureLabelSystem(dtEntity::EntityManager& em); + ~TextureLabelSystem(); + + osg::StateSet* GetSymbolStateset(const std::string& symbolpath, TextureLabelComponent& component); + + void SetupLabel(TextureLabelComponent& component); + + void SetEnabled(bool v); + bool GetEnabled() const; + + private: + + dtEntity::DynamicBoolProperty mEnabled; + bool mEnabledVal; + osg::ref_ptr mProgram; + }; +} diff --git a/external/dtEntity/include/dtEntityOSG/transformcomponent.h b/external/dtEntity/include/dtEntityOSG/transformcomponent.h new file mode 100644 index 000000000..a898d0d68 --- /dev/null +++ b/external/dtEntity/include/dtEntityOSG/transformcomponent.h @@ -0,0 +1,97 @@ +#pragma once + +/* -*-c++-*- +* dtEntity Game and Simulation Engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 2.1 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Martin Scheffler +*/ + +#include +#include +#include +#include +#include +#include +#include + +namespace dtEntityOSG +{ + + /////////////////////////////////////////////////////////////////////////// + /** + * abstract base class for transform components + */ + class DTENTITY_OSG_EXPORT TransformComponent + : public GroupComponent + { + typedef GroupComponent BaseClass; + + public: + + static const dtEntity::ComponentType TYPE; + + TransformComponent(osg::Transform* trans); + + virtual ~TransformComponent(); + + virtual dtEntity::ComponentType GetType() const { + return TYPE; + } + + + virtual dtEntity::Vec3d GetTranslation() const = 0; + virtual void SetTranslation(const dtEntity::Vec3d&) = 0; + + virtual dtEntity::Vec3d GetScale() const { return dtEntity::Vec3d(1,1,1); } + virtual void SetScale(const dtEntity::Vec3d&) {} + + virtual dtEntity::Quat GetRotation() const = 0; + virtual void SetRotation(const dtEntity::Quat&) = 0; + + virtual dtEntity::Matrix GetMatrix() const + { + dtEntity::Matrix matrix; + matrix.setTrans(GetTranslation()); + matrix.setRotate(GetRotation()); + return matrix; + } + + virtual void SetMatrix(const dtEntity::Matrix& mat) + { + SetTranslation(mat.getTrans()); + SetRotation(mat.getRotate()); + } + + + private: + + }; + + /////////////////////////////////////////////////////////////////////////// + class DTENTITY_OSG_EXPORT TransformSystem + : public dtEntity::EntitySystem + { + public: + TransformSystem(dtEntity::EntityManager& em) + : dtEntity::EntitySystem(em) + { + } + + dtEntity::ComponentType GetComponentType() const { return TransformComponent::TYPE; } + }; + +} diff --git a/external/dtEntity/lib64/libdtEntity.so b/external/dtEntity/lib64/libdtEntity.so new file mode 120000 index 000000000..0183d9681 --- /dev/null +++ b/external/dtEntity/lib64/libdtEntity.so @@ -0,0 +1 @@ +libdtEntity.so.2 \ No newline at end of file diff --git a/external/dtEntity/lib64/libdtEntity.so.0.1.1 b/external/dtEntity/lib64/libdtEntity.so.0.1.1 new file mode 100755 index 000000000..c691fd252 Binary files /dev/null and b/external/dtEntity/lib64/libdtEntity.so.0.1.1 differ diff --git a/external/dtEntity/lib64/libdtEntity.so.2 b/external/dtEntity/lib64/libdtEntity.so.2 new file mode 120000 index 000000000..257695a5e --- /dev/null +++ b/external/dtEntity/lib64/libdtEntity.so.2 @@ -0,0 +1 @@ +libdtEntity.so.0.1.1 \ No newline at end of file diff --git a/external/dtEntity/lib64/libdtEntityOSG.so b/external/dtEntity/lib64/libdtEntityOSG.so new file mode 120000 index 000000000..9e055e170 --- /dev/null +++ b/external/dtEntity/lib64/libdtEntityOSG.so @@ -0,0 +1 @@ +libdtEntityOSG.so.2 \ No newline at end of file diff --git a/external/dtEntity/lib64/libdtEntityOSG.so.0.1.1 b/external/dtEntity/lib64/libdtEntityOSG.so.0.1.1 new file mode 100755 index 000000000..0e66d4e11 Binary files /dev/null and b/external/dtEntity/lib64/libdtEntityOSG.so.0.1.1 differ diff --git a/external/dtEntity/lib64/libdtEntityOSG.so.2 b/external/dtEntity/lib64/libdtEntityOSG.so.2 new file mode 120000 index 000000000..923f2de15 --- /dev/null +++ b/external/dtEntity/lib64/libdtEntityOSG.so.2 @@ -0,0 +1 @@ +libdtEntityOSG.so.0.1.1 \ No newline at end of file