| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#if !defined( INCLUDED_IENTITY_H ) |
| 23 |
#define INCLUDED_IENTITY_H |
| 24 |
|
| 25 |
#include "generic/constant.h" |
| 26 |
|
| 27 |
#include "string/string.h" |
| 28 |
#include "scenelib.h" |
| 29 |
|
| 30 |
class EntityClass; |
| 31 |
|
| 32 |
typedef Callback<void(const char*)> KeyObserver; |
| 33 |
|
| 34 |
class EntityKeyValue |
| 35 |
{ |
| 36 |
public: |
| 37 |
virtual ~EntityKeyValue() = default; |
| 38 |
virtual const char* c_str() const = 0; |
| 39 |
virtual void assign( const char* other ) = 0; |
| 40 |
virtual void attach( const KeyObserver& observer ) = 0; |
| 41 |
virtual void detach( const KeyObserver& observer ) = 0; |
| 42 |
}; |
| 43 |
|
| 44 |
class Entity |
| 45 |
{ |
| 46 |
public: |
| 47 |
STRING_CONSTANT( Name, "Entity" ); |
| 48 |
|
| 49 |
class Observer |
| 50 |
{ |
| 51 |
public: |
| 52 |
virtual void insert( const char* key, EntityKeyValue& value ) = 0; |
| 53 |
virtual void erase( const char* key, EntityKeyValue& value ) = 0; |
| 54 |
virtual void clear() { }; |
| 55 |
}; |
| 56 |
|
| 57 |
class Visitor |
| 58 |
{ |
| 59 |
public: |
| 60 |
virtual void visit( const char* key, const char* value ) = 0; |
| 61 |
}; |
| 62 |
|
| 63 |
virtual const EntityClass& getEntityClass() const = 0; |
| 64 |
virtual void forEachKeyValue( Visitor& visitor ) const = 0; |
| 65 |
virtual void setKeyValue( const char* key, const char* value ) = 0; |
| 66 |
virtual const char* getKeyValue( const char* key ) const = 0; |
| 67 |
virtual bool isContainer() const = 0; |
| 68 |
virtual void attach( Observer& observer ) = 0; |
| 69 |
virtual void detach( Observer& observer ) = 0; |
| 70 |
}; |
| 71 |
|
| 72 |
class EntityCopyingVisitor : public Entity::Visitor |
| 73 |
{ |
| 74 |
Entity& m_entity; |
| 75 |
public: |
| 76 |
EntityCopyingVisitor( Entity& entity ) |
| 77 |
: m_entity( entity ){ |
| 78 |
} |
| 79 |
|
| 80 |
void visit( const char* key, const char* value ){ |
| 81 |
if ( !string_equal( key, "classname" ) ) { |
| 82 |
m_entity.setKeyValue( key, value ); |
| 83 |
} |
| 84 |
} |
| 85 |
}; |
| 86 |
|
| 87 |
inline Entity* Node_getEntity( scene::Node& node ){ |
| 88 |
return NodeTypeCast<Entity>::cast( node ); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
template<typename value_type> |
| 93 |
class Stack; |
| 94 |
template<typename Contained> |
| 95 |
class Reference; |
| 96 |
|
| 97 |
namespace scene |
| 98 |
{ |
| 99 |
class Node; |
| 100 |
} |
| 101 |
|
| 102 |
typedef Reference<scene::Node> NodeReference; |
| 103 |
|
| 104 |
namespace scene |
| 105 |
{ |
| 106 |
typedef Stack<NodeReference> Path; |
| 107 |
} |
| 108 |
|
| 109 |
class Counter; |
| 110 |
|
| 111 |
class EntityCreator |
| 112 |
{ |
| 113 |
public: |
| 114 |
INTEGER_CONSTANT( Version, 2 ); |
| 115 |
STRING_CONSTANT( Name, "entity" ); |
| 116 |
|
| 117 |
virtual scene::Node& createEntity( EntityClass* eclass ) = 0; |
| 118 |
|
| 119 |
typedef void ( *KeyValueChangedFunc )(); |
| 120 |
virtual void setKeyValueChangedFunc( KeyValueChangedFunc func ) = 0; |
| 121 |
|
| 122 |
virtual void setCounter( Counter* counter ) = 0; |
| 123 |
|
| 124 |
virtual void connectEntities( const scene::Path& e1, const scene::Path& e2, int index ) = 0; |
| 125 |
|
| 126 |
virtual void setLightRadii( bool lightRadii ) = 0; |
| 127 |
virtual bool getLightRadii() const = 0; |
| 128 |
virtual void setShowNames( bool showNames ) = 0; |
| 129 |
virtual bool getShowNames() = 0; |
| 130 |
virtual void setShowTargetNames( bool showNames ) = 0; |
| 131 |
virtual bool getShowTargetNames() = 0; |
| 132 |
virtual void setShowAngles( bool showAngles ) = 0; |
| 133 |
virtual bool getShowAngles() = 0; |
| 134 |
|
| 135 |
virtual void printStatistics() const = 0; |
| 136 |
}; |
| 137 |
|
| 138 |
#include "modulesystem.h" |
| 139 |
|
| 140 |
template<typename Type> |
| 141 |
class GlobalModule; |
| 142 |
typedef GlobalModule<EntityCreator> GlobalEntityModule; |
| 143 |
|
| 144 |
template<typename Type> |
| 145 |
class GlobalModuleRef; |
| 146 |
typedef GlobalModuleRef<EntityCreator> GlobalEntityModuleRef; |
| 147 |
|
| 148 |
inline EntityCreator& GlobalEntityCreator(){ |
| 149 |
return GlobalEntityModule::getTable(); |
| 150 |
} |
| 151 |
|
| 152 |
#endif |