/
GComponentInterface.h
92 lines (81 loc) · 1.7 KB
/
GComponentInterface.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#pragma once
#include "GObject.h"
#include "GFactory.h"
enum eComponentType
{
eComponentType_Trans,
eComponentType_Mesh,
eComponentType_Ani,
eComponentType_Effect,
eComponentType_Script,
eComponentType_Box,
eComponentType_Particles,
eComponentType_Count,
};
class GNode;
class GComponentInterface :
public GObject
{
public:
GComponentInterface ( void );
virtual ~GComponentInterface ( void );
void setOwner(GNode* target);
GNode* getOwner() const;
protected:
eComponentType mComponentType;
GNode* mOwner;
bool mCanDetach;
public:
inline eComponentType getType()
{
return mComponentType;
}
inline const char* getComponentName()
{
return categoryName();
}
inline bool canDetach() const
{
return mCanDetach;
}
inline void setCanDetach ( bool can )
{
mCanDetach = can;
}
};
template<eComponentType TYPE>
class GComponentBase: public GComponentInterface
{
public:
enum{ComponentType=TYPE,};
virtual void set()
{
};
GComponentBase()
{
mComponentType = TYPE;
}
};
class GComponentOwner
{
public:
GComponentOwner();
~GComponentOwner();
GComponentInterface* getComponent ( const char* name ) const;
GComponentInterface* getComponent ( eComponentType type ) const;
GComponentInterface* attachComponent ( eComponentType type);
GComponentInterface* attachComponent ( const char* name);
void detachComponent ( const char* name );
void detachComponent ( eComponentType type );
protected:
GComponentInterface* mCompoents[eComponentType_Count];
};
#define DeclareComponentCreator(className) \
public:\
static GComponentInterface* createComponent() \
{\
return new className;\
}
#define DeclareComponentType(className)\
DeclareCategoryName(className)\
DeclareComponentCreator(className)